- Home /
enable disable object script error?
been trying to figure this out for hours so can anyone help me?
the script is to be attached to an is trigger collider and supposed to enable me to drag an object that is disabled into the script window and have the object be enabled while the player is inside the trigger area and disabled again on exit. but i keep getting the error at the bottom.
var cube : GameObject;
function OnTriggerEnter () {
cube.GameObject.Active(true);
}
function OnTriggerExit () {
cube.GameObject.Active(false);
}
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.Invoke (System.Object target, System.String name, System.Object[] args) UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType) onoff.OnTriggerEnter () (at Assets/onoff.js:5)
please halp! going insane haha!
Answer by Unitraxx · Apr 06, 2013 at 11:41 PM
since cube is already of type GameObject
, you should not use
cube.GameObject.Active(...);
but
cube.SetActive(...);
edit : And I guess you also want to use SetActive()
instead of just Active()
.