Hello guys, I want to build a shop and i have created a character selection mode until now. So basicly i have a script that looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CharacterSelection : MonoBehaviour {
private GameObject[] characterList;
private int index;
public string lvltoload = "MainLevel";
private void Start()
{
index = PlayerPrefs.GetInt("CharacterSelected");
characterList = new GameObject[transform.childCount];
for (int i = 0; i < transform.childCount; i++)
{
characterList *= transform.GetChild(i).gameObject;*
}
foreach (GameObject go in characterList)
{
go.SetActive(false);
}
if (characterList[index])
{
characterList[index].SetActive(true);
}
}
public void ToggleLeft()
{
characterList[index].SetActive(false);
index -= 1;
if(index < 0)
{
index = characterList.Length - 1;
}
characterList[index].SetActive(true);
}
public void ToggleRight()
{
characterList[index].SetActive(false);
index += 1;
if (index == characterList.Length)
{
index = 0;
}
characterList[index].SetActive(true);
}
public void ConfirmButton()
{
PlayerPrefs.SetInt(“CharacterSelected”, index);
SceneManager.LoadScene(lvltoload);
}
}
And i want the user to firstly buy the character and after that to select it. But i don’t know how to do it. I was thinking to set a playerprefs but i don’t know how to set it (the script) for each index. For example if index 1(character 1) has the PlayerPrefs (“CharacterSold”, 0) then the button select to be inactive. And now the player should buy the character. So the PlayerPrefs becomes 1 and now the select button is active. Can you help me with that?