- Home /
Toggle Menu Not Working
Dear Coders Can anyone help? I have created a scrolling menu which allows me to add one of two sprites to the transform of an empty gameobject.
On scene loading, the first sprite (Index 0) appears. If I implement buyCharacter, it adds it to my existing empty gameObject. However, I cannot then scroll through to the next character.
However, on scene loading if I toggle right to the second sprite, I can implement buyCharacter and the sprite will be added to my empty game object after which I can then toggle left to the first sprite.
Would anyone have any suggestions as to how I would be able to add either sprite and 'buy' it and still be able to access the other?
Thankyou in advance!
public List chooseSprite;
public int index;
public GameObject characterSelector;
public GameObject currentSprite;
[HideInInspector] public PickPlayer pPlayer;
[HideInInspector] public List <GameObject> pPlayerList;
public void Start ()
{
List <GameObject> chooseSprite = new List<GameObject> ();
for (int i = 0; i < chooseSprite.Count; i++) {
if (chooseSprite [index]) {
chooseSprite [index].SetActive (true);
}
}
public void Update (){
currentSprite = chooseSprite [index];
if(Input.GetKeyDown(KeyCode.A)){
buyCharacter();
}
}
public void ToggleLeft(){
chooseSprite [index].SetActive (false);
index--;
if (index < 0)
index = chooseSprite.Count - 1;
chooseSprite [index].SetActive (true);
}
public void ToggleRight ()
{
chooseSprite [index].SetActive (false);
index++;
if (index == chooseSprite.Count)
index = 0;
chooseSprite [index].SetActive (true);
}
public void buyCharacter (){
for (int i = 0; i < chooseSprite.Count; i++) {
chooseSprite.Remove (currentSprite);
FindObjectOfType<SkinAdding> ().AddPlayer ();
index++;
if (index == chooseSprite.Count)
index = 0;
}
}
Your answer
Follow this Question
Related Questions
List of bools assigned to each Gameobject in List/Array 0 Answers
A node in a childnode? 1 Answer
How to add an item to a list with a class/uJS struct? 1 Answer
multi dimensional array of lists 1 Answer
In a group of gameobjects, how to have only one object active at a time while disabling the others? 2 Answers