I have a coin system where when you get a coin, you get a point. There are multiple coins in the system. Apart of that is a coin that subtracts life and one that gives. I’m using the same coin system for the original. There are two scripts as seen here.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CoinCounter : MonoBehaviour
{
public static int coinCount;
public static int lifeCount;
public GameObject coinageDisplay;
public GameObject lifeDisplay;
public int internalCoinage;
public int internalLife;
void Update ()
{
internalCoinage = coinCount;
coinageDisplay.GetComponent<Text>().text = "" + coinCount;
internalLife = lifeCount;
lifeDisplay.GetComponent<Text>().text = "" + lifeCount;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Coin : MonoBehaviour
{
public enum Amount { one, five, ten, fifty, N_one, N_five, N_ten, N_fifty, G_one };
public Amount type;
public GameObject theCoin;
public GameObject coinDisplayBox;
void OnTriggerEnter2D(Collider2D other)
{
if (type == Amount.one)
{
coinDisplayBox.SetActive(true);
CoinCounter.coinCount += 1;
theCoin.SetActive(false);
}else if (type == Amount.five)
{
coinDisplayBox.SetActive(true);
CoinCounter.coinCount += 5;
theCoin.SetActive(false);
}else if (type == Amount.ten)
{
coinDisplayBox.SetActive(true);
CoinCounter.coinCount += 10;
theCoin.SetActive(false);
}else if (type == Amount.fifty)
{
coinDisplayBox.SetActive(true);
CoinCounter.coinCount += 50;
theCoin.SetActive(false);
}else if (type == Amount.N_one)
{
coinDisplayBox.SetActive(true);
PlayerHealth.currentHealth -= 1;
theCoin.SetActive(false);
}else if (type == Amount.N_five)
{
coinDisplayBox.SetActive(true);
PlayerHealth.currentHealth -= 5;
theCoin.SetActive(false);
}else if (type == Amount.N_ten)
{
coinDisplayBox.SetActive(true);
PlayerHealth.currentHealth -= 10;
theCoin.SetActive(false);
}else if (type == Amount.N_fifty)
{
coinDisplayBox.SetActive(true);
PlayerHealth.currentHealth -= 50;
theCoin.SetActive(false);
}else if (type == Amount.G_one)
{
coinDisplayBox.SetActive(true);
PlayerHealth.currentHealth += 1;
theCoin.SetActive(false);
}
}
}
The real problem is with this line
internalLife = lifeCount;
lifeDisplay.GetComponent<Text>().text = "" + lifeCount;
And this is also going to take in the fact that there is a subtraction coin too. Is there something I can do, or do I need a seprate script?