- Home /
Making more than one item appear on a chess board
hi,am making a game where stuff appears on a chess board and the player clicks etc etc.Currently i have one item appearing on a random position on the board but i don't know how to make more than one item appear. Someone please help
var cube1:GameObject;
var cube2:GameObject;
var clone:GameObject;
var obj:GameObject[];
var spawnPoints:GameObject[];
function Start () {
spawnPoints=GameObject.FindGameObjectsWithTag("spawn");
Call();
}
function Update () {
}
function Call(){
yield WaitForSeconds(2);
var randomPosition=Random.Range(0,spawnPoints.Length);
var randomObj=Random.Range(0,obj.length);
//spawnPoints.RemoveAt(randomPosition);
Debug.Log(randomPosition);
clone=Instantiate(obj[randomObj],spawnPoints[randomPosition].transform.position,Quaternion.Euler(0,180,0));
clone.name="Object";
//Destroy(obj[randomObj]);
//obj.RemoveAt(randomObj);
}
Answer by ArkaneX · Aug 29, 2013 at 12:04 PM
You can change Call method to include count parameter (number of objects you want to spawn):
function Call(count : int){
yield WaitForSeconds(2);
for(var i : int = 0; i<count; i++) {
// whole random and instantiate stuff for single object
}
}
And then for example execute Call(5). If you need to introduce additional delay between spawning objects, then add additional yield inside the for loop.
Answer by EBR · Aug 29, 2013 at 12:35 PM
You could add a for loop so that it instantiates a chess piece for every x amount.
var inst_amount : int = 1; //The amount of chess pieces you want to instantiate
for(int i = 0; i <= inst_amount - 1; i++)
{ *instantiate chess piece here* }