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<GameObject, float> ItemPrices;
void Start ()
{
scoreText.text = "Score : " + ((int)PlayerPrefs.GetFloat ("Highscore")).ToString();
ItemPrices = new Dictionary<GameObject, float>()
{
{ Item1, 100f },
{ Item2, 2500f },
{Item3, 3500f},
{ Item4, 5000f },
};
}
public void PurchaseItem(GameObject Item)
{
foreach(KeyValuePair<GameObject, float> 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