- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
el-santia93 · Aug 26, 2013 at 04:23 PM ·
javascriptarrays
Problem removing items from array
I have a problem removing items from an array. please help. Here's my code:
var i :int;
var clone:GameObject;
var obj:GameObject[];
var spawnPoints:GameObject[];
spawnPoints=GameObject.FindGameObjectsWithTag("spawn");
function Start () {
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);
//var quest=spawnPoints[randomPosition];
Debug.Log(Random.Range(0,spawnPoints.Length));
clone=Instantiate(obj[randomObj],spawnPoints[randomPosition].transform.position,Quaternion.identity);
clone.name="Object";
obj.RemoveAt(randomObj);
}
Comment
Answer by perchik · Aug 26, 2013 at 04:34 PM
Your first problem is that line 5 needs to be inside of the start function instead of on its own.
Second, the Debug.Log statement on line 21 doesn't do what you expect, because it picks a new random number in that range. You probably want to replace that with Debug.Log(randomPosition);
Your answer
Follow this Question
Related Questions
going through each item of a multi-dimensional array 1 Answer
How to find the index of an Object in an Array 2 Answers
Advance through array elements with math (++)? 1 Answer
Getting C# to access a javascript global Array and Components 1 Answer
How would I call upon an asset in the projects tab with an array? 1 Answer