- Home /
Array Index is Out Of Range...
Hey guys/girls, I have a error on my multiplayer fps game... There my code :
if(equipe != "" && estMort == true){
if(GUI.Button(Rect(5, 10, 200, 20), "Spawn")){
var aleatoire = Random.Range(0, 7);
if(equipe == "rouge"){
Network.Instantiate(joueur, spawn_bleu[aleatoire].transform.position, spawn_bleu[aleatoire].transform.rotation, 0);
}
if(equipe == "bleu"){
Network.Instantiate(joueur, spawn_bleu[aleatoire].transform.position, spawn_bleu[aleatoire].transform.rotation, 0);
}
You don't say what line and you don't give us much context. The most likely culprit is here:
var aleatoire = Random.Range(0, 7);
That is, you don't tie 'aleatorie' to the number of entries in spawn_blue. Change to:
var aleatoire = Random.Range(0, spawn_bleu.Length);
This assumes that spawn_blue is a built in array. Use '.Count' for .Net collections. Note you will still get an Out of Range error if the size of spawn_bleu is 0.
Putting "Help" into the title or into the tags doesn't actually help you. The title of the question and it's tags are looked at by people searching through unanswered questions. If all they see is "help" they're not going to visit your question.
Your answer

Follow this Question
Related Questions
[Editor] How to use System.Collections.Generic in a UnityScript Editor Script 1 Answer
Sprite animation with large number of images 0 Answers
Images collections in panel 0 Answers
Convert To UnityScript 1 Answer
Unknown identifier 2 Answers