character select (code attacted) how to make lock /unlock system?
Hi friends, I have a simple character select screen left right to select character models. I have attached the code.
Can someone please advise on how i can get ie 1st character free, 2nd character 100 coins`3rd character 100 coins etc.
Thanks very much for any assistance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CharacterSelection : MonoBehaviour
{
private GameObject[] characterList;
private int index;
private void Start()
{
index = PlayerPrefs.GetInt ("characterSelected");
characterList = new GameObject[transform.childCount];
//fill the array with our models
for(int i = 0; i < transform.childCount; i++)
characterList [i] = transform.GetChild (i).gameObject;
//We toggle the renderer to hide objects
foreach (GameObject go in characterList)
go.SetActive (false);
//we toggle the sellected character
if (characterList [index])
characterList [index].SetActive (true);
}
public void ToggleLeft()
{
//toggle off the current model
characterList [index].SetActive (false);
index--; //index -= 1; index = - 1;
if (index < 0)
index = characterList.Length - 1;
//toggle on the new model
characterList [index].SetActive (true);
}
public void ToggleRight()
{
//toggle off the current model
characterList[index].SetActive(false);
index++; //index -= 1; index = - 1;
if (index == characterList.Length)
index = 0;
//toggle on the new model
characterList[index].SetActive(true);
}
public void ConfirmBtn()
{
PlayerPrefs.SetInt("characterSelected", index);
SceneManager.LoadScene ("Game");
}
}
Comment