I made a script where you collect coins, the issue is that the coin variable will always be set back to 0 for gameplay purposes so I created another variable for stockpiling the coins the player collected. I don’t understand why when I collect 12 coins, the actual amount in the shop is above 1,000. I need it to stockpile accurately, just basic addition.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NewMechanics : MonoBehaviour
{
public Text coinText;
private float coins;
public Text stockText;
private float stockValue = 0f;
void Start()
{
coins = 0f;
}
// Update is called once per frame
void FixedUpdate()
{
stockText.text = stockValue.ToString("0,000");
stockValue += coins;
coinText.text = coins.ToString("0");
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject.tag == “coin”)
{
coins += 1f;
}
}