- Home /
Question by
digitaldebonaire · May 01, 2014 at 02:58 AM ·
nullreferenceexceptionaccessteleport
How to access a second script on same object
I have a script that teleports an object that collides with an object tagged TeleportIn
var target : Transform;
var pathScript : Enemy_GroundUnit;
function Awake()
{
//connect to outbound teleporter
target = GameObject.FindWithTag("TeleportOut").GetComponent(Transform);
}
function Update ()
{
}
function OnTriggerEnter (col : Collider)
{
//need TeleportIn tag on TeleportIn Object
if(col.gameObject.tag == "TeleportIn")
{
this.transform.position = target.position;
pathScript.GetNewPath();
}
}
I am getting a NullReferenceException from the bottom line
pathScript.GetNewPath();
The script Enemy_GroundUnit is attatched to the same object and has a function called GetNewPath. I want to call it after the object telports. Am I calling it wrong or is this something wrong with that script?
Comment
Best Answer
Answer by 0V3RR1D3 · May 01, 2014 at 03:05 AM
to reference the script do this
gameObject.GetComponent(Enemy_GroundUnit).GetNewPath();