Question by
SpatialQuotient · Jun 11, 2018 at 09:26 PM ·
triggertextfloatscore system
Coin counter using public float losing score over time?
I am making a game where if an object with a certain tag triggers the object the script is attached to it adds +15 to the score. I am using public float And public Text to add to the text counter. I have a Text UI on a canvas to keep score. Here is my AddCoin code:
public float Coins;
public float PreviousCoins;
public Text CoinText;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "myObject")
Coins = PreviousCoins + 15;
PreviousCoins = Coins;
CoinText.text = Coins.ToString();
}
Pretty simple code right? and it works, The problem is; the score keeps going back down over time. What could be causing this and how do I stop it?
Thanks in advance
Comment
Best Answer
Answer by UnbreakableOne · Jun 11, 2018 at 09:39 PM
I would suggest making it into a property, then see who tries to access it. Makes debugging much simpler.