- Home /
components and variables - inspector problems
very simple question (hopefully) with s simple answer. I got a script from one of my friends and it used public variables to get the components<, in unity 5 how do I declare what component it should be associated with?
(I tried the little circle thing and nothing came up)
public GameObject nameOfVariable; // will be a game object
public Rigidbody nameOfVariable2; // will be a rigidbody
Answer by sadowlight123 · Aug 05, 2017 at 04:28 PM
after the monobehavior line you do :
public typeofvariable nameofvariable example: public Rigidbody myrigid ;
in start you assign : nameofvariable = getcomponent(); example: myrigid = getcomponent();
in other functions such as update , you can access through : nameofvariable.anyfunction(etc) example: myrigid.velocity() etc..
Hope it helps
Your answer
Follow this Question
Related Questions
Where can I find a complete list of Attributes and how they work and 2 Answers
How do I get the grid layout component? 0 Answers
Inspector vs Script: Component best practice? 1 Answer
How to change array orders in the inspector 1 Answer
Inspector Component Icon - change for derived as well? 0 Answers