I have been having problems with my score update text. Sometimes when I collect a game object, when it is supposed to go up by 50 every time it is collected, it goes up by some random number like 50 to 150, or it will stay at 100 even though I picked up another coin. How do I fix this? P.S. If you are asking why I have 2 different codes, it is because I have been using tutorials.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScoreSystem : MonoBehaviour
{
public AudioSource soundCollected;
void OnTriggerEnter(Collider other)
{
soundCollected.Play();
Collectible.score += 50;
Debug.Log(Collectible.score);
Destroy(gameObject);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Collectible : MonoBehaviour
{
public GameObject scoreText;
public static int score = 0;
void Update()
{
scoreText.GetComponent<Text>().text = "SCORE: " + score;
}
}