Count/score counter only updates when all instances of object have been collected?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GemScript : MonoBehaviour {
public int rotateSpeed;
public AudioSource GemSound;
public GameObject Gem;
public Text omgText;
public int score;
// Update is called once per frame
void Update () {
transform.Rotate(0, rotateSpeed, 0);
Counting();
}
private void OnTriggerEnter(Collider other)
{
GemSound.Play();
score = +1;
omgText.text = "Count: " + score.ToString ();
Counting();
Gem.SetActive(false);
}
private void Counting()
{
omgText.text = "Score: " + score.ToString();
}
}
I have managed to make the Text object count whenever you collide with the gem in this case. But if I turn the gem into a prefab and duplicate the prefab within the editor the counter only updates when all the gems have been collected. I'm new to unity and I'm not sure why this happens.
Comment