Right now i have a game where you can play any level in any order. For the players to unlock something i want to set each of these items level unlock number to a random level that has not been completed yet.
So right now what i do is go through all levels that are not complete and add this to a list of type int,
Then i go through each of my items and assign them a random level number and remove this said number from a list so the next cycle can now choose between numbers that are available to be selected.
But for some reason its allowing a number to be chosen more than once.
// Here we need to know if the levels are 1 or 2
public void FindRandomFaceToUnlockItemOn()
{
// Go through each element in the array
// Pick a random number
// Remove the number from the array
// Set the number as one of the items levels to unlock something
foreach(var ci in createdItems)
{
rNumber = Random.Range(levelsToUnlockSomething[0], levelsToUnlockSomething[levelsToUnlockSomething.Count - 1]);
if (!ci.GetComponent<UnlockableItem>().isUnlocked)
{
levelsToUnlockSomething.Remove(rNumber);
ci.GetComponent<UnlockableItem>().LevelToUnlockMe = rNumber;
}
Debug.Log("Chosen number for this level is " + ci.GetComponent<UnlockableItem>().LevelToUnlockMe + "And the length of the array is now : " + levelsToUnlockSomething.Count);
}
// Assign the last item to -1 as this can only be unlocked when the last level is complete
createdItems[createdItems.Count - 1].GetComponent<UnlockableItem>().LevelToUnlockMe = -1;
}
Aucun commentaire:
Enregistrer un commentaire