Hello, I am making a store system in my game where you can buy characters and in each character I have 2 buttons one with the price to buy that is in setactive state (true) by default and the other that is a check that is in setactive (false) and that when the purchase comes the buy button disappears and the check button appears I have 10 characters so I created a public GameOBject [ ] Hide to hide the buttons once purchased and another public GameOBject [ ] Toshow to show the check that they are in a for, in the inspector I drag my buttons to the public variable of the array and at the moment of buying let’s say the first one that is in index [0] the same thing happens automatically with the 10 characters and I know that it is because I am going from 1 in 1 in my for. My question is how to stop when the first one stops and does not apply to other objects and when I buy the second or fifth only the setactive is applied in those index [ ] Please help me. I leave my code here.
public class ShopManager : MonoBehaviour
{
public GameObject[] Hide;
public GameObject[] Toshow;
public void CharacterButtonPressed(int prices)
{
if(Singleton.instance.totalCoins>prices)
{
Singleton.instance.totalCoins -= prices;
BuyPressedTrue();
BuyPressedFalse();
Debug.Log("Acabas de comprar");
}else
{
{
if(Singleton.instance.totalCoins<prices)
{
Debug.Log("No tienes dinero");
}
}
}
}
public void BuyPressedFalse()
{
for (int i = 0; i < Hide.Length; i++)
{
Hide[i].SetActive(false);
}
}
public void BuyPressedTrue()
{
for (int i = 0; i < Toshow.Length; i++)
{
Toshow[i].SetActive(true);
}
}
}