I have 2 scripts.
script 1:
var waarde : boolean;
function Awake(){
waarde = false;
}
script 2:
var waarde:boolean;
var script1;
function Awake(){
script1 = this.gameObject.GetComponent(script1);
waarde = script1.waarde; <-- NullReference?
}
You can not know which of the objects will be initialize first.
For this reason, you should wait a frame before looking for other objects.
Do this in script 2:
function Awake()
{
StartCoroutine(Initiate());
}
private function Initiate()
{
yield;
script1 = this.gameObject.GetComponent(script1);
waarde = script1.waarde;
}
KeithK
3
You should only setup references in the Awake function. Like the line below is perfect:
script1 = this.gameObject.GetComponent(script1);
As for getting information like the value you want from that boolean. Do that in the Start function of Script 2 instead.
function Start()
{
waarde = script1.waarde;
}
This is because you cannot be sure that the Awake function of Scrip 1 is called before that of Script 2’s.