Hello recently I implemented a shop system which I have mostly down. The one problem is if the player has no money it will not charge them but the adding of the item will still continue which I want to stop if the player doesnt have enough money. I need this to stop the script from another script.
Shop Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class Shop : ActionItem
{
public GameObject ManaPotion;
public GameObject CoinSystem;
public AudioSource BuyPotion;
public AudioClip BuyPotionClip;
private void Start()
{
BuyPotion.clip = BuyPotionClip;
}
public void BuyManaPot()
{
CoinSystem.GetComponent<CoinSystem>().SubtractCoins(10);
{
inventory.AddItem(ManaPotion);
BuyPotion.Play();
}
}
}
Coin System
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class CoinSystem : MonoBehaviour {
public int Coins;
public Text CoinText;
// Use this for initialization
void Start () {
Coins = 0;
}
public void AddCoins(int CoinsToAdd)
{
Coins += CoinsToAdd;
CoinText.text = "Coins:" + Coins;
}
public void SubtractCoins(int CoinsToSubtract)
{
if(Coins - CoinsToSubtract < 0)
{
SubtractCoins(0);
Debug.Log("You Didn't Have Enough Money!");
return;
}
else
{
Coins -= CoinsToSubtract;
}
}
}
In the SubtractCoins method if I dont have enough I want it to send something to the other script telling it to stop the process of completing the code in the BuyManaPot() Method. Thank you!