void Awake() { int speed = 60; int price = 1000; int chk = PlayerPrefs.GetInt("chk", 0); if (chk == 0) { PlayerPrefs.SetInt("chk", 1); for (int i = 0; i < transform.childCount; i++) { string temp = (transform.GetChild(i)).ToString(); carClass obj = new carClass(); obj.topSpeed = speed; speed += 10; obj.price = price; if (i != 0) { price += 500; } obj.CarID = i; if (i != 0) { obj.isLocked = true; } else { obj.isLocked = false; } string json = JsonUtility.ToJson(obj); PlayerPrefs.SetString(temp, json); } PlayerPrefs.SetInt("coins", 100); } }
public void ClickedBuy() { int coins = PlayerPrefs.GetInt("coins"); int price = 0; string nme = (transform.GetChild(currentCar)).ToString(); string p = PlayerPrefs.GetString(nme); if (p != null && p.Length > 0) { carClass obj = JsonUtility.FromJson <carClass>(p); price = obj.price; obj.isLocked = false; string json = JsonUtility.ToJson(obj); PlayerPrefs.SetString(nme, json); } PlayerPrefs.SetInt("coins", coins - price); MoneyTxt.text = "$" + (PlayerPrefs.GetInt("coins")).ToString(); lockImg.SetActive(false); selectB.SetActive(true); Debug.Log(PlayerPrefs.GetInt("coins")); buyB.SetActive(false); }
private void SelectCar(int _index) { previous.interactable = (_index != 0); next.interactable = (_index != transform.childCount - 1); string nme = (transform.GetChild(_index)).ToString(); string p = PlayerPrefs.GetString(nme); if (p != null && p.Length > 0) { carClass obj = JsonUtility.FromJson <carClass>(p); price.text = "$ " + (obj.price).ToString(); CarTopSpeedText.text = (obj.topSpeed).ToString() + "Kms/hr"; if (obj.isLocked == false) { lockImg.SetActive(false); buyB.SetActive(false); if (obj.CarID == SelectedCarInt) { Selected.gameObject.SetActive(true); selectB.SetActive(false); } else { selectB.SetActive(true); Selected.gameObject.SetActive(false); } } else { Selected.gameObject.SetActive(false); lockImg.SetActive(true); if (PlayerPrefs.GetInt("coins") >= obj.price) { buyB.GetComponent <Button>().interactable = true; } else { buyB.GetComponent <Button>().interactable = false; } selectB.SetActive(false); buyB.SetActive(true); } } /* if (PlayerPrefs.GetInt(nme,0)==1) * { * lockImg.SetActive(false); * selectB.SetActive(true); * buyB.SetActive(false); * } * else * { * lockImg.SetActive(true); * selectB.SetActive(false); * buyB.SetActive(true); * * }*/ for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).gameObject.SetActive(i == _index); transform.GetChild(i).gameObject.transform.localScale = new Vector3(1f, 1f, 1f); } }