- Home /
How can I make my buying system work and some more doubts
My shop system script is not working 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
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
KEEP INSTANTIATE PREFAB ONMOUSEDOWN 1 Answer