Question by
RecyclingBen · Dec 22, 2016 at 11:02 PM ·
getcomponent
Using GetComponent
I've been trying to take a variable from a different class, with a small problem.
here is my script:
private Rotation_Pivot rotation_Pivot;
void Awake()
{
rotation_Pivot = GetComponent<Rotation_Pivot>();
}
void Start ()
{
}
void Update ()
{
if (Input.GetKey("down"))
{
rotation_Pivot.rotationLeft += 500;
}
}
I took a tutorial from here https://unity3d.com/learn/tutorials/topics/scripting/getcomponent to do this.
Now, I don't see any errors directly in my script. In Unity itself, though, I get
NullReferenceException: Object reference not set to an instance of an object
this takes place in line 18.
Could anyone help me to understand what I'm doing wrong?
Comment
Try and move the GetComponent to the Start method ins$$anonymous$$d, also check script execution order. The code looks correct.
Your answer