- Home /
Question by
AbominationGames · Jun 11, 2014 at 08:32 PM ·
arrayarraysrangeout
Array out of range
Error:
IndexOutOfRangeException: Array index is out of range.
RespawnMonster+$Start$151+$.MoveNext () (at Assets/ActionRPGKit/Script/RespawnMonster.js:10)
Script:
#pragma strict
var enemy : Transform;
//var point = 10;
var pointName : String = "SpawnPoint";
var delay : float = 3.0;
var randomPoint : float = 10.0;
function Start () {
var spawnpoints : GameObject[] = GameObject.FindGameObjectsWithTag (pointName);
var spawnpoint : Transform = spawnpoints[Random.Range(0, spawnpoints.length)].transform;
yield WaitForSeconds (delay);
var ranPos : Vector3 = spawnpoint.position; //Slightly Random x y position from respawn point.
ranPos.x += Random.Range(0.0,randomPoint);
ranPos.z += Random.Range(0.0,randomPoint);
Instantiate(enemy, ranPos , spawnpoint.rotation);
Destroy (gameObject, 1);
}
I'm lost...
Comment
Just to be clear: Do you know what an IndexOutOfRangeException exeption is?
Best Answer
Answer by Jeff-Kesselman · Jun 11, 2014 at 08:34 PM
Random .Range goes from A to B inclusive http://docs.unity3d.com/ScriptReference/Random.Range.html
The maximum index on an array is always length-1.
When all else fails, read the docs
Your answer
Follow this Question
Related Questions
Array out of Range 1 Answer
Array index is out of Range!? 1 Answer
Wierd Animation Bug 0 Answers
array problem index out of range ? why ? 2 Answers
Array out of its own range? 4 Answers