Good morning guys
I have a list of a class like:
[System.Serializable]
public class Person {
public string Name;
public string Surname;
public int dateOfBirth;
}
public class NewScript1 : Monobehaviour {
public Person[] People;
...
}
This is not the script, but a similar.
The problem comes when I make it code-generate I mean something like this:
public void GeneratePeople (int length) {
People = new Person (length);
for (int i = 0; i < People.Length; i ++) {
GeneratePeople (i);
}
}
public void GeneratePeople (int index) {
Person per = new Person ();
per.Name = Names[(int) Mathf.Round (Random.Range (0, Names.Length-1))];
per.Surname = Surnames [(int) Mathf.Round (Random.Range (0, Surnames.Length-1))];
per.dateOfBirth = (int) Mathf.Round (Random.Range (1900, 2000));
People[index] = per;
}
I have tried using a loop, and it assign to the hole list the same value, then I have tried to do it manually. It assign to the hole list the last value.
Why? How can I fix this?
Please Help.
Thanks
New Dev