So I’m getting a null reference exception and I can’t figure out how to fix it. Heres the code and line its on.
private var ship : GameObject;
private var planets : Array;
private var stuckDistance : float;
private var planet : GameObject;
function Start () {
ship = GameObject.Find("Ship");
planets = new Array();
planets.length = 4;
planets[0] = GameObject.Find("Planet_1");
planets[1] = GameObject.Find("Planet_2");
planets[2] = GameObject.Find("Planet_3");
planets[3] = GameObject.Find("Planet_4");
stuckDistance = 15.0f;
}
function Update () {
for (var p = 0; p < 4; p++)
{
if((Vector3.Distance (transform.position, planets[p].transform.position)) <= stuckDistance)
{
planet = planets[p];
}
}
transform.position = planet.transform.position;//line with null exception
refueling = true;
}
my working theory right now is maybe i have to declare the array differently? I'm looking at the scripting reference but I'm not seeing anything very helpful. anyone have any ideas?