- Home /
Question by
GroundstompStudios · May 24, 2019 at 03:46 PM ·
c#c# tutorialshopcurrency
How to create a shop system?
Hi, I am making a 2D platformer and I want to make a shop system where they can upgrade their player. I am new to coding so I was wondering if some people can help me. I want to upgrade the health of the player while it shows them spending points. I don't want an inventory system, I just want it so when they hit a button to upgrade the player, it spends the points and upgrades their health.
SHOP SCRIPT:
public GameObject environment;
public GameObject HP;
public GameObject lives;
public GameObject shopMenu;
private void Start()
{
Time.timeScale = 0;
shopMenu.SetActive(true);
environment.SetActive(false);
HP.SetActive(false);
lives.SetActive(false);
}
public void Continue()
{
Time.timeScale = 1;
shopMenu.SetActive(false);
environment.SetActive(true);
HP.SetActive(true);
lives.SetActive(true);
}
public void BuyItem()
{
}
public void OnClick()
{
FindObjectOfType<AudioManager>().Play("Click");
}
public void OnHover()
{
FindObjectOfType<AudioManager>().Play("Hover");
}
PLAYER HEALTH SCRIPT
public int startingHealth = 100;
public int currentHealth;
public GameObject player;
bool dead;
bool damaged;
[Header("UI Components")]
public Text healthText;
public Fallout fallout;
private void Awake()
{
currentHealth = startingHealth;
}
public void Update()
{
healthText.text = "HEALTH: " + currentHealth.ToString();
damaged = false;
}
public void TakeDamage (int amount)
{
damaged = true;
FindObjectOfType<AudioManager>().Play("Hit");
currentHealth -= amount;
if (currentHealth <= 0 && !dead)
Die();
}
void Die()
{
dead = true;
Destroy(player);
print("Player died.");
FindObjectOfType<AudioManager>().Play("PlayerDeath");
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612202028im_/https://answers.unity.com/themes/thub/images/avi.jpg)