- Home /
Question by
Jakesie · Oct 15, 2012 at 09:30 AM ·
triggernullreferenceexeption
Instance error on trigger
Hi there, I want to usea simple object that I've attached to a prefab. However, I cannot get it to work correctly, as it keep giving me an error.
My script: var target: Transform;
public function Start (){
if (target == null && GameObject.FindWithTag("Player"))
target = GameObject.FindWithTag("Player").transform;
}
function OnTriggerEnter() {
if(target.GameObject.FindWithTag == "Player"){
collider.isTrigger = true;
print ("Triggered");
}
}
and the error message is this:
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.GetProperty (System.Object target, System.String name) UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name) KeyForDoor.OnTriggerEnter () (at Assets/Custom Assets/Scripts/KeyForDoor.js:10)Blockquote
Comment
if(target.GameObject.FindWithTag == "Player") doesn't make sense to me do you mean if(target.gameObject.tag == "Player") ? or do you want to check if there is a game object in the scene with the player tag? if(GameObject.FindWithTag("Player")) also I believe your OnTriggerEnter function should be function OnTriggerEnter(var collider) {
}