How do you add to an array with "...[]" & reset a selector to avoid duplication
I'm working with Vector3[] but yet apparently .RemoveAt or .Push or .Add won't work. As said in this
Also... since I asked... does this code go through the array and checks whether there are duplicate positions.. then if there is resets the coin position until there is a different position AKA validates until the selector position is unique
private var CoinPosSelector : int; //The randomiser for coin positioning
private var SpawnPoints : Vector3[]; //Coordinates for all spawn points
private var PointsUsed : Vector3[];
function Start ()
{
CoinPosSelector = Random.Range (1, SpawnPoints.Length);
for (var i : int = 0; i < PointsUsed.Length; i++)
{
while(PointsUsed[i] == CoinPosSelector)
{
CoinPosSelector = Random.Range (1, SpawnPoints.Length); //Chooses new position
}
}
PointsUsed.Add(CoinPosSelector);
}
With
PointsUsed[i] == CoinPosSelector
you are comparing a Vector3 with an int in line 11
I guess you mean
PointsUsed[i] == SpawnPoints[CoinPosSelector]
Thanks man.. now I feel like a fool for that blunder :D Will fix it
Your answer
Follow this Question
Related Questions
Copy random GameObjects in an Array and add to a list. Without having duplicates in the list 0 Answers
Why does this loop throw an error if int questComplete rises above 1? 0 Answers
Managing In-Game Variables of Different Data Types 1 Answer
Defining a number of gameobjects from another gameobject 0 Answers