add else if statement to character select to load a scene per each character based on index condition
Hi I am following a tutorial on youtube and this is the code so far for character selection, it works perfectly, however I want to be able to load a scene depending on which character has been chosen, I think I can do this with an else if statement checking if the index is true and if it is load level 1 else load level 2
Here is the code hope anyone can help.
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement;
public class CharacterSelection : MonoBehaviour { private GameObject[] characterList; private int index; private void Start() { characterList = new GameObject[transform.childCount];
// Fill the Array with our character select screen models
for (int i = 0; i < transform.childCount; i++)
characterList [i] = transform.GetChild (i).gameObject;
// Toggle off mesh renderer for the models
foreach (GameObject go in characterList)
go.SetActive (false);
// Toggle on the 1st index in the array aka switch the 1st model on to display in character select screen within the code array
if (characterList [0])
characterList [0].SetActive(true);
}
public void ToggleLeft()
{
// Toggle off current model
characterList[index].SetActive(false);
index--; // index -= 1; index = index - 1; other ways of doing the same command or statement
if (index < 0)
index = characterList.Length - 1;
// Toggle on new model
characterList[index].SetActive(true);
}
public void ToggleRight()
{
// Toggle off current model
characterList [index].SetActive (false);
index++;
if (index == characterList.Length)
index = 0;
// Toggle on new model
characterList [index].SetActive (true);
}
public void ConfirmButton()
{
SceneManager.LoadScene ("Bedroom4");
}
}
Your answer
Follow this Question
Related Questions
IndexOutOfRangeExeption! This doesent even affect my gameplay, it just is there to be annoying! 1 Answer
Unknown Argument Out of Range Index Error On Card Game 1 Answer
[help] Array index is out of range 0 Answers
I need help finding the index of an object in a list. 1 Answer
[SOLVED]Removing gameobject from list don't change the index 1 Answer