Hey guys, I currently have an item collector script which does pretty much what you’d expect. I have 2 controllable characters on my project and when i tried using the script, they both had their own counters for some reason. What i mean is that I collected a few items with one of them and then switched into the other one and tried to collect another item but the counter started from 0 because they’re not sharing the same value even though I don’t have anything on the code that makes it do that. Any ideas?
using UnityEngine;
using UnityEngine.UI;
public class ItemCollector : MonoBehaviour
{
public Text scoreText;
private int goldAmount;
void Start()
{
goldAmount = 0;
scoreText.text = "Golds : " + goldAmount;
}
private void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Collectables")
{
goldAmount += 1;
Destroy(other.gameObject);
scoreText.text = "Golds : " + goldAmount;
}
}
}