Hi! you'll see, i have this scripts that i made, i have 8 letters i wanna spawn in 11 possible spots, i want each letter to be assign to one unique location, but when i run the script, some letters are spawned at the same spot. What am i doing wrong? :I Thnks! :b
var letter : GameObject[]; //prefabs that will be spawned
var letterSpot : GameObject[]; //Empty GameObjects where the prefabs will spawn
var spotUsed : boolean[]; //wether the spot is already used or not
private var letterIndex : int;
function Start ()
{
PutLetter(0);
PutLetter(1);
PutLetter(2);
PutLetter(3);
PutLetter(4);
PutLetter(5);
PutLetter(6);
PutLetter(7);
}
function PutLetter (i : int)
{
letterIndex = Random.Range(0,10);
while (spotUsed == true)
{
letterIndex = Random.Range(0,10);
}
Instantiate(letter[i], letterSpot[letterIndex].transform.position, letterSpot[letterIndex].transform.rotation);
spotUsed[letterIndex]=true;
}
↧