- Home /
Change color of the object based on previous player's choice
Hi! I've have 2 scenes with selection choice. To access the scene second with for example weapons, you have to choose character in the first scene. I would like to change color of the weapons based on which character I choose in the character selection scene. How do I approach this if everything works on arrays ?
Here's my script with that I implement in character selection scene:
public class CharacterSelection : MonoBehaviour
{
private GameObject[] characterList;
private int index;
private void Start()
{
index = PlayerPrefs.GetInt("CharacterSelected");
characterList = new GameObject[transform.childCount];
//array w players
for (int i = 0; i < transform.childCount; i++)
characterList[i] = transform.GetChild(i).gameObject;
foreach (GameObject go in characterList)
go.SetActive(false);
if (characterList[index])
characterList[index].SetActive(true);
}
public void ToggleLeft()
{
characterList[index].SetActive(false); //turning off the old character
index --;
if (index < 0)
index = characterList.Length - 1;
characterList[index].SetActive(true);
}
public void ToggleRight()
{
characterList[index].SetActive(false); //turning off the old character
index++;
if (index == characterList.Length)
index = 0;
characterList[index].SetActive(true);
}
public void GoBackToCharacter()
{
PlayerPrefs.SetInt("CharacterSelected", index);
SceneManager.LoadScene("WeaponSelect");
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Toggle ON/OFF MaterialChange 0 Answers
Game manager Object reference not set to an instance of an object 1 Answer