Shop C# and coin safe like a money
i don't know how to make my hero to can go through coins and how to mark it like a money i made script and i had a coin but i can't get it and also i don't know how to make powerup upgrade i mean how to increase powerup duration like an upgrade exemple:powerup +10 health duration:10 sec after buy the increase powerup duration upgrade to be something like that powerup +10 health duration:15sec i already have a powerup and all is okey i need help only for the upgrade here some of my scripts using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class GameControl : MonoBehaviour {
public Text moneyText;
public static int moneyAmount;
int isPowerupSold;
public GameObject powerup;
void Start () {
moneyAmount = PlayerPrefs.GetInt("MoneyAmount");
isPowerupSold = PlayerPrefs.GetInt("isPowerupSold");
if (isPowerupSold == 1)
powerup.SetActive(true);
else
powerup.SetActive(false);
}
void Update () {
moneyText.text = "Money: " + moneyAmount.ToString() + "$";
}
public void LoadShope()
{
Time.timeScale = 1f;
PlayerPrefs.SetInt("MoneyAmount", moneyAmount);
SceneManager.LoadScene("Shop");
}
}
///////////////////////////////////////// ,`using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class ShopControl : MonoBehaviour
{
int moneyAmount;
int isPowerupSold;
public Text moneyAmountText;
public Text powerupPrice;
public Button buyButton;
// Use this for initialization
void Start()
{
moneyAmount = PlayerPrefs.GetInt("MoneyAmount");
}
// Update is called once per frame
void Update()
{
moneyAmountText.text = "Money: " + moneyAmount.ToString() + "$";
isPowerupSold = PlayerPrefs.GetInt("IsPowerupSold");
if (moneyAmount >= 1000 && isPowerupSold == 0)
buyButton.interactable = true;
else
buyButton.interactable = false;
}
public void buyPowerUP()
{
moneyAmount -= 1000;
PlayerPrefs.SetInt("IsPowerupSold", 1);
powerupPrice.text = "Sold!";
buyButton.gameObject.SetActive(false);
}
public void exitShop()
{
PlayerPrefs.SetInt("MoneyAmount", moneyAmount);
SceneManager.LoadScene("Menu");
}
public void resetPlayerPrefs()
{
moneyAmount = 0;
buyButton.gameObject.SetActive(true);
powerupPrice.text = "Price: 1000$";
PlayerPrefs.DeleteAll();
}
}`
and for the coin too
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Coin : MonoBehaviour {
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
GameControl.moneyAmount += 1;
Destroy(gameObject);
}
}