what I'm trying to do here is to set a button active and disable another button By pressing a Button, and Save this action on game Restarting.
I tried this code below but not working.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
public class BuySmoke : MonoBehaviour {
private int i;
public int Price;
private int CoinIhave;
public Button BuYsmoke;
public GameObject buy;
void Start () {
i =Convert.ToInt32 (buy);
CoinIhave = PlayerPrefs.GetInt ("CoinBank");
}
public void Buy(){
if (CoinIhave >= Price) {
CoinIhave -= Price;
PlayerPrefs.SetInt ("CoinBank", CoinIhave);
BuYsmoke.gameObject.SetActive (true);
gameObject.SetActive (false);
PlayerPrefs.SetInt ("selected", i);
}
if (CoinIhave < Price) {
Debug.Log ("Not Enough Coin");
}
}
}
I tried this method by changing Object to int then using the playerPrefs but it doesn't work.
and yes I have the PlayerPrefs.GetInt("selected") on the maincamera
so please any help or advise even links to tutorial will be appreciated.
↧