asked in Software by (8.2k points)
0 like 0 dislike
53 views

How I can to get certain variable of game object in Unity game engine?

unity gameobject get variable

1 Answer

0 like 0 dislike
answered by (8.2k points)

Just game object don't containt something variables. All possible variables contain in components, what a object have.

Accessing a variable on MonoBehaviour is normally a three step process:

  1. Get a reference to the appropriate GameObject.
  2. Get a reference to the appropriate Component with "GetComponent" method.
  3. Access a public member with a operator point.

Step one can often be skipped if you drag and drop references in the inspector, use a singleton, pass in a component reference, or any number of other approaches.

Example

GameObject.GetComponent<ClassName>().VariableName = 5;

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

Related questions

0 like 0 dislike
1 answer 57 views
0 like 0 dislike
1 answer 48 views
0 like 0 dislike
1 answer 16 views
0 like 0 dislike
1 answer 7 views
0 like 0 dislike
1 answer 19 views
0 like 0 dislike
1 answer 24 views
0 like 0 dislike
1 answer 33 views
...