- Home /
Function OnTriggerEnder (difficult JavaScript)
Ok hi all my code is below and i am stuck cause i cant define the object that enters the trigger zone
var MonsterBody : Transform;
function OnTriggerEnter (other : Collider) {
if (other.tag == "Alive") {
MonsterBody.GetComponent("Hostile-AI").PerceptionCollision = true;
}
}
function OnTriggerExit (other : Collider) {
if (other.tag == "Alive") {
MonsterBody.GetComponent("Hostile-AI").PerceptionCollision = false;
}
}
Now in the script called Hostile-AI i have this ( which is my problem )
if (PerceptionCollision == true) {
transform.LookAt(Vector3(GetComponent("PerceptionArea-Trigger-AI").other.transform.parent.transform.position.x, transform.position.y, GetComponent("PerceptionArea-Trigger-AI").other.transform.parent.transform.position.z));
}
The error that I get 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) Hostile-AI.Update () (at Assets/MyScripts/Mob AI/Hostile-AI.js:54)
Answer by NightmarexGR · May 01, 2013 at 11:56 AM
I am so idiot , i was calling for a script that wasnt there at first place transform.LookAt(Vector3(GetComponent("PerceptionArea-Trigger-AI") Should be transform.LookAt(Vector3(PerceptionArea.GetComponent("PerceptionArea-Trigger-AI")