Hi! I've been having trouble making a character selection screen for my game. My goal is to make a character selection scene where you could purchase characters with coins that you collect from the game. I created the scripts from what I've learned from these two videos: [Character Select Scene][1] and [Simple Shop][2].
I combined the two videos, what I came up with is a character select screen similar to the first video with a buy button![alt text][3]
All the character models are attached to an empty game object called player models with this script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CharacterScript : MonoBehaviour
{
private GameObject[] characterList;
private int index;
private void Start()
{
index = PlayerPrefs.GetInt("CharacterSelected");
characterList = new GameObject[transform.childCount];
for(int i = 0; i= 50 && isBought1 == 0)
{
buyButton1.interactable = true;
confirmButton1.interactable = false;
}
else if (coinAmount1 >= 50 && isBought1 == 1)
{
buyButton1.interactable = false;
confirmButton1.interactable = true;
}
else if (coinAmount1 <= 50 && isBought1 == 0)
{
confirmButton1.interactable = false;
buyButton1.interactable = false;
}
else if (coinAmount1 <= 50 && isBought1 == 1)
{
confirmButton1.interactable = true;
buyButton1.interactable = false;
}
}
public void BuyButton()
{
coinAmount1 -= 50;
PlayerPrefs.SetInt("IsBought", 1);
buyButton1.gameObject.SetActive(false);
}
}
which is in each of the character models. When I press buy on one model, it purchases every single other character in the game even though I only bought the first one which does not make sense given the fact that I duplicated every single button there is. Another problem is that my gold is reduced when hovering over the character I bought but when I switch to a different character my gold is back where it started. I am open to remaking this character select menu and I will accept all suggestions
Sorry for the long post I just wanted to make this as detailed as possible, thanks in advance
[1]: https://www.youtube.com/watch?v=IFTjcPvCZaM&t=599s
[2]: https://www.youtube.com/watch?v=G_I6GxGIB_Y&t=2s
[3]: /storage/temp/164742-character-select.jpg
↧