Hello
I don’t understand what happened.
I made a class with static property for manage the level and the sequence of enemy scene. The class is called globalData
I have another class called randomNumbers for calculate random number in a range. These numbers cannot be repeated. the method is called randomScene.
globalData has a private static method call loadingOrderScenes() for load a list.
When I comment the line where add new numbers to the list. The program run well. But when I put this line active. Unity no responding.
I think is because is cyclized.
What can i do?
public class globalData : MonoBehaviour {
//this property is for manage the sequence of enemy scene
public static List <int> orderScena;
// this property manage a level
public static int Level = 1;
// this property manage the characte for the user.
public static int personaje = 2;
public static void loadingOrderScenes()
{
RandomNumbers NumbersRandom;
NumbersRandom = new RandomNumbers();
int cantDatos = 0;
int number = 0;
orderScena = new List<int>();
orderScena.Add(personaje);
try {
Debug.Log("it going to enter " + orderScena.Count);
while (true)
{
number = NumbersRandom.randomScene(1,6);
if (!orderScena.Contains(number))
{
Debug.Log("it is on the While = " + cantDatos);
// HERE IS THE PROBLEM..................................
//orderScena.Add(number);
cantDatos ++;
}
if ( cantDatos == 7)
{
Debug.Log("it is on the while = " + cantDatos);
break;
}
}
orderScena.Add(7);
Debug.Log("is out: " + orderScena.Count);
}
catch (UnityException e)
{
Debug.LogError(e);
}
}
// this is the other method
public int randomScene(int min, int max)
{
int number = 0;
number = Random.Range(min , max);
return number;
}
Incidentally, the reason why it only locks up when you have that extra line of code is because before then, your new value has not been entered into the List, therefore the if-statement continues to execute, even though it found the number before, and so cantDatos is still incremented and exits at the break on reaching 7.
– richyrichThanks for dedicate your time to answer. I changed my code and used these tips. And it works ! good day
– Ion_Leo