Quantcast
Channel: Latest Questions by Reid
Viewing all articles
Browse latest Browse all 4

How do I fix this NullReferenceException?

$
0
0

ok I am trying to have an object move to another object "target" then once it is there move to another object "target"

I thought my script would make this happen but I got this error "NullReferenceException: Object reference not set to an instance of an object" and I have no clue about how to fix it I don't think it is caused by my script but it might so here is what I have

var target1 : GameObject;
var target2 : GameObject;
var sit : int = 5;
var speed : float = 1;
private var point;

function Awake ()
{
    transform.position = target1.transform.position;
}

function Update ()
{
    sit -= Time.time;
    transform.position = point;
}//update


function OnTriggerEnter (other : Collider)
{
    if(other.tag == "target1"){
        Debug.Log("hit target1");
        if (sit <= 0){
            point = target2.transform.position * speed * Time.deltaTime;
        }
    }
    if(other.tag == "target2"){
        Debug.Log("hit target2");
        if (sit <= 0){
            point = target1.transform.position * speed * Time.deltaTime;
        }
    }
}//ontriggerenter

any help would be greatly appreaciated thanks in advanced


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images