Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

How to Save Object (Button) information on game restarting? please check code.

$
0
0
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.

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>