Hey guys, ive been away from unity scripting for a month or two, and its made me forget lots of the basics. I cant seem to work out why this script isn’t working.
var Player : Transform;
function OnTriggerEnter( Player: Collider)
{
var other : run_away_enemy = gameObject.GetComponent(run_away_enemy);
other.change_come ();
}
function OnTriggerExit( Player: Collider)
{
var other : run_away_enemy = gameObject.GetComponent(run_away_enemy);
other.change_run ();
}
When the game is running, if the player enters and exits the collider, these are the errors I get.
“NullReferenceException: Object reference not set to an instance of an object on_trigger_swarm.OnTriggerExit (UnityEngine.Collider Player) (at Assets/Scripts/on_trigger_swarm.js:16)”
and
" NullReferenceException: Object reference not set to an instance of an object on_trigger_swarm.OnTriggerEnter (UnityEngine.Collider Player) (at Assets/Scripts/on_trigger_swarm.js:8)"
I don’t think its relevant…but these are the functions that I am trying to call.
function change_come ()
{
Debug.Log ("true");
attack = true;
}
function change_run()
{
Debug.Log ("false");
attack = false;
}
Any help would really be appreciated!
Thanks