- Home /
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
Follow this Question
Related Questions
How to Change Character Sprite from Script 0 Answers
Selector de personaje, Character selector 0 Answers
Character selection 1 Answer
Character Selection (Change Material) 0 Answers