Character selection
Hi everyone,
I want to make character selection in my game like in Voodoo did in Dune, Dunk Hit, Flappy Dunk, etc. Game should have for example 20 characters and if for each character there would be challenge to complete. When player complete challenge the unlock skin. If anyone has some tutorial on that question I would be more than thankful because I am trying to figure out solution for days and I only got some code but I am stuck at most important part. Here is code:
public GameObject shopButtonPrefab;
public GameObject shopButtonContainer;
public Sprite[] playerSkin;
private void Start()
{
ChangePlayerSkin(GameManager.instance.currentSkinIndex);
int textureIndex = 0;
Sprite[] textures = Resources.LoadAll<Sprite>("Player");
foreach(Sprite texture in textures)
{
GameObject container = Instantiate(shopButtonPrefab) as GameObject;
container.GetComponent<Image>().sprite = texture;
container.transform.SetParent(shopButtonContainer.transform, false);
int index = textureIndex;
container.GetComponent<Button>().onClick.AddListener(() => ChangePlayerSkin(index));
textureIndex++;
}
}
private void ChangePlayerSkin(int index)
{
Debug.Log(index); // here should be code for changing sprite image
GameManager.instance.currentSkinIndex = index;
GameManager.instance.Save();
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612151627im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Array of Texts that change dynamic on selected character 0 Answers
instantiating player to different scenes 0 Answers
Character shop 1 Answer
How do I save a previously bought characters in my Game? 0 Answers
Plane character selector unity problem 0 Answers