I’m having an array index out of range problem that I just can’t seem to solve :S Does anyone have an idea? I’ve been looking it over and can’t seem to locate the problem
currentWaypointLocation = -1;
var whichShell = ball.GetComponent("BallController").currentWaypointLocation;
ball.GetComponent("BallController").SetPosition(shells[whichShell].transform.localPosition.x, shells[whichShell].transform.localPosition.z);
ball.GetComponent("BallController").Show();
code addn
//Start with the middle one - base all other positions off the middle
shells[1].transform.localPosition.x = this.transform.localPosition.x;
shells[1].transform.localPosition.z = this.transform.localPosition.z;
shells[0].transform.localPosition.x = shells[1].transform.localPosition.x - .30;
shells[0].transform.localPosition.z = shells[1].transform.localPosition.z;
shells[2].transform.localPosition.x = shells[1].transform.localPosition.x + .30;
shells[2].transform.localPosition.z = shells[1].transform.localPosition.z;
//Starting 'numbers'
shells[0].GetComponent("ShellController").curPositionNum = 0;
shells[1].GetComponent("ShellController").curPositionNum = 1;
shells[2].GetComponent("ShellController").curPositionNum = 2;
//Set Reference Numbers -- For checking if user selects right shell later
shells[0].GetComponent("ShellController").shellReference = 0;
shells[1].GetComponent("ShellController").shellReference = 1;
shells[2].GetComponent("ShellController").shellReference = 2;
//Ball Stuff
ball.GetComponent("BallController").currentWaypointLocation = Random.Range(0,299) % 3; //Pick a position for the ball to start in
ball.transform.localPosition.x = shells[ ball.GetComponent("BallController").currentWaypointLocation ].transform.localPosition.x; //Set the position of the ball to whichever shell it is attached to
ball.transform.localPosition.y = shells[ ball.GetComponent("BallController").currentWaypointLocation ].transform.localPosition.y;
ball.transform.localPosition.z = shells[ ball.GetComponent("BallController").currentWaypointLocation ].transform.localPosition.z;
for( var ii=0; ii < shells.length; ii++ )
{
//If we're the first object
if( shells[ii].GetComponent("ShellController").curPositionNum == whichMove[0] )
{
//Set positions, and start moving
shells[ii].GetComponent("ShellController").localStartPosition = shells[ii].transform.localPosition;
shells[ii].GetComponent("ShellController").localEndPosition = shellPositionWaypoints[ whichMove[1] ];
shells[ii].GetComponent("ShellController").endPositionNum = whichMove[1];
shells[ii].GetComponent("ShellController").EnableMove();
}
if( shells[ii].GetComponent("ShellController").curPositionNum == whichMove[1] )
{
//Set positions, and start moving
shells[ii].GetComponent("ShellController").localStartPosition = shells[ii].transform.localPosition;
shells[ii].GetComponent("ShellController").localEndPosition = shellPositionWaypoints[ whichMove[0] ];
shells[ii].GetComponent("ShellController").endPositionNum = whichMove[0];
shells[ii].GetComponent("ShellController").EnableMove();
}
}
bAllReachedDestination = false; //No more setting coords, for now
}
//Stop moving shells when we hit the max number of moves
function StopWhenMovesDone() : boolean
{
if( curMoveNumber >= numMovesThisRound )
{
bRoundOver = true; //Round is over! NO MORE!
bRoundChoice = true;
//Make sure to put the Ball under the shell!
var whichShell = ball.GetComponent("BallController").currentWaypointLocation;
ball.GetComponent("BallController").SetPosition( shells[whichShell].transform.localPosition.x, shells[whichShell].transform.localPosition.z); //Set new position of whichever shell it's under!
ball.GetComponent("BallController").Show(); //Make the ball visible again!