I can’t seem to figure out why I’m getting this error, but I’m sure it must be a simple explanation, can someone please help? I have these two scripts which I have attached to 2 different cubes :
Script 1:
private var variableInstance;
var variable : int = 0;
function Start () {
variableInstance = GetComponent(script2);
}
function OnMouseDown () {
variableInstance.variable2 = variable;
}
Script 2:
var variable2 : int = 5;
I have the first script attached to one cube and the second attached to the other cube. I believe this should allow me to click on cube one and the value for “variable” should be set to the value of “variable2”. But obviously its not working, I get no compiling errors until I enter play mode and click on the first cube. what am I doing wrong?
Also here’s the exact error:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
script1.OnMouseDown () (at Assets/script1.js:12)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)