Hello guys… I have a little problem over here with a public and static array…
The problem explained
I have a so-called “champion select”, where the players choose 3 characters to play with. After clicking one of the 10 buttons with all the characters, I put the champion ID in an array. This way, in the end, I will have an array called playerID with 7 elements (from 1 to 6, I don’t use position 0) and each element will tell me what champion the player wanted to play with… I put a DontDestroyOnLoad function for this script where I only declared the playerID and change the scene to the actual game. Afterwards, in the game, I have a sceneHandler empty object, where I take the information from the characterHandlerScript, and based on the array, I spawn those certain champions. The problem is only the first champion is spawned (out of all 6), whatever his model (I mean whatever the champion which the player has picked). Here is some code…
Part of the getCharacterToBox script
if (amCompletat == false && buton1.GetComponentInChildren<Text> ().text=="?") {
buton1.GetComponentInChildren<Text> ().text = buttonWhichIHaveJustClickedOn.GetComponentInChildren<Text>().text;
amCompletat = true;
characterHandlerScript.playerID [1] = int.Parse (buton1.GetComponentInChildren<Text> ().text);
print ("a");
}
Explanation for getCharacterToBox
amCompletat is a variable that helps me see which of the 3 boxes are still incomplete. The buttons with characters each have text on them equal to a number. For instance, for the fourth champion, its button will have the text “4”. Everything seems cool when selecting the champions. I put the print(“a”) over there to see if the “if” statement is ran, and it is… But the array thingy got weird.
The whole characterHandlerScript
public static int[] playerID = new int[7];
void Awake () {
DontDestroyOnLoad (transform.gameObject);
}
Part of the sceneHandler script
for (int i = 1; i <= 6; i++)
{
if (characterHandlerScript.playerID[i] == 1)
{
if (i <= 3)
spawnedPlayerpi = Instantiate(characterModel[1], playerSpawnPosition[i], Quaternion.identity) as GameObject;
else
{
spawnedPlayerpi = Instantiate(characterModel[1], playerSpawnPosition[i], Quaternion.identity) as GameObject;
spawnedPlayerpi.transform.Rotate(Vector3.up, 180f);
}
Explanation for the sceneHandler script
In the very first “if” I’m checking if the first character is character number 1. If so, I spawn him from the characterModel array with the position from playerSpawn Position. It’s pretty simple…
If you wish for any further explanation for this code, just let me know by leaving a comment… I’d really like to have someone helping me out with this problem…