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

My shop system script is not working

$
0
0
Hi, I am trying to make a shop system but my script is not working. when I press buy button it doesn't deduct the cost from the overall score also I want display a message if player don't have enough points and the buy button changes to equip button after player bought the gameobject and a way to save the purchase in playerprefs or txt file and how will I change the gameobject that player equiped in the game scene please explain these all here is the script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using UnityEngine.EventSystems; public class shop : MonoBehaviour { public TMPro.TextMeshProUGUI scoreText; public GameObject Item1; public GameObject Item2; public GameObject Item3; public GameObject Item4; private Dictionary ItemPrices; void Start () { scoreText.text = "Score : " + ((int)PlayerPrefs.GetFloat ("Highscore")).ToString(); ItemPrices = new Dictionary() { { Item1, 100f }, { Item2, 2500f }, {Item3, 3500f}, { Item4, 5000f }, }; } public void PurchaseItem(GameObject Item) { foreach(KeyValuePair item in ItemPrices) { if (item.Key == Item) { // Take away the cost of the item from the player's currency float score = PlayerPrefs.GetFloat ("Highscore"); score -= item.Value; } } } } thanks

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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