showing results for - "getcomponent"
Maxence
14 Sep 2020
1ur so stoopid u dum its eeeeeeez to use getcomponent jkust doo
2
3Getcomponent<*A component to get*>().*the thing you need in the component* *100/= true/= false/ color.red
Ida
13 Apr 2016
1 //First script 
2public class Enemy : MonoBehaviour{
3  public int health = 10;
4  public void saySomething(){
5    Debug.Log("Hi, i am an enemy.");
6  } 
7}
8//Second script
9//There is one thing though,
10//if the script is located on another gameobject,
11//which will be most likely, you have to somehow
12//find that gameobject first. There are many ways of
13//doing it, via raycast, collision,
14//trigger, find by tag, find by gameobject etc.
15//But i will use the simplest way to understand,
16//that is declaring public GameObject in player script,
17//which contains Enemy, and later you just drag and drop the
18//gameobject in the inspector.
19public class Player : MonoBehaviour{
20  //Drag and drop gameobject with script Enemy in inspector
21  GameObject enemyGameObject;
22  void Start(){       
23    //We get Enemy component - script
24    //from public gameobject which contains this script
25    Enemy enemyScript = enemyGameObject.GetComponent<Enemy>();
26    //This will debug Enemy health is: 10  
27    Debug.Log("Enemy health is:"+ enemyScript.health)  
28      //This will debug "Hi, i am an enemy." 
29      enemyScript.saySomething();  
30  } 
31}
Jacobo
11 Jul 2019
1using UnityEngine;
2
3public class TryGetComponentExample : MonoBehaviour
4{
5    void Start()
6    {
7    	// Since Unity  2019.2 you can use TryGetComponent to check
8        // if an object has a component, it will not allocate GC in 
9        // the editor if the object doesn't have one.
10        if (TryGetComponent(out Rigidbody rigidFound))
11        {
12        	// Deactivate rigidbody
13            rigidFound.enabled = false;
14        }
15        
16		// For versions below 2019.2 you can do it this way:
17        // Create a variable
18        Rigidbody rigidFound = GetComponent<Rigidbody>();
19        
20        // If the 'Rigidbody' exist in the gameobject
21        if(rigidFound != null)
22        {
23        	// Deactivate rigidbody
24            rigidFound.enabled = false;
25        }
26	}
27}
Giorgio
22 Oct 2017
1public Gameobject a; //this allows you to drag an object into a slot in the unity software
2private transform b; //this is a variable that can only be assigned and altered in script
3
4b = a.GetComponent<Transform>(); //this finds the transform component of 'a' and assigns that to 'b'
queries leading to this page
unity get componetunity getcomponent 3c 3e 28 29 3fc 23 unity what does getcomponentgetcomponent unityunity get component scriptgetcomponent reactunity getcomponent methodunity get component of gameobjectunity c 23 get components of componentunity getting componentgetcomponent script unityaccording to unity e2 80 99s scripting api 2c the following are valid options for the component getcomponent method 3awhen using getcomponent in a script 2c what goes between the 3c 3e 3funity get component functionunity getcomponent 3c 3e 28 29getcomponent 3c 3e 28 29get componentjavascript getcomponentunity getting componentsunity c 23 get component unity get componentunity play function get componentunity get component sriptget this component unitywhat game object does gameobject getcomponents get 3fget component game object unitypublic component unityget component owner unityget componenetunity getcomponenethow do you access a component inside of a script unityhow to get component in unityunity get object with component getcomponent 3ct 3e unitywww how to use getcomponent in unitygetcomponent unity c 23get component in playerget component from gameobject unityunity get component in cildunity how to get component scriptwhat game object does gameobject getcomponent get 3funity c 23 getcomponent scriptgetcomponent 28 29unity getcomponent of typeget component in start unityunity do get component scripthow to get component on a gameobjectscript get component in unity getcomponentget component variable unityunity get object componentget component script unityghow to use getcomponent to get a gameobject from the hierarchygetcomponents 3ccomponent 3e 28 29unity 2d getcomponent voidunity get an a 2a componentgameobject getcomponentunity get component of this objectunity c 23 find game objectget the componet unityunity get component of typeunity gameobject get componentunity get component from gameobjectgetcomponentinparent getting component on objectunity get component of an objectunity get component of cmaerahow to get component from current objectunity getcomponent explainedunity getcomponent gameobjectgetcomponent in component basedc 23 unity getcomponentget component in unityunity get component of current objecyget all component unity unity getcomponentunity component getunity get component on same objectunity get component through scriptunity gameobject getcomponentunity get object componentsunity get component by namehow to get component in unity c 23unity player getcomponet 3cmove2s 3eunity 2d getcomponenttry get component unityuse getcomponent unityunity getcomponent 3ccomponent 3eget component c 23 unityunity find componentunity getcomponent doesgetcomponent of gameobject unityunity get component via scriptunity getcomponent commandunity getcomponentsunity getcomponetnc 23 unity get set componentunity get component in updateuntiy get componentunity getcomponent moeve2dhow to get componentgetcomponent in unity c 23get compotnent of the self object unity apifind component unityget component untyhow to get component unityget component in starthow to get a component from an object in unityget component unity c 23unity get component with propertyfindcomponent unitygetcomponent 3ct 3e unitygetcomponent gameobject unity c 23 getcomponent unitygameobject getcomponent 3c 3e 28 29get components unityhow to get a component in unityunity get componentunity get component script is onunity store get componentunity getcomponent gaemanagerunity get component from objectget component in child unityfind component unity3dgo get componenthow to get a component of n object unitygetcomponent 3c 3e 28 29 3bunity get 3c 3eunity getcomponent dockhow to use get component unityhow to use getcomponent unityget compnent unityunity get component c 23unity get componenteunity require componentunity c 23 getcomponenthow to get a componenet in unityget component name unityunity getcom 5bponentget component unity scripthow to find a component unityget component unity methodget component unityunity get componenetunity 2d how get a componentunity automatically get componentget component for transform unity docsgetcomponents javascripthow heavy is get component unityunity trygetcomponent cshow to use unity get componentunity get componentshow to get compoment unityunity trygetcomponent diasemblegetcomponent