One textUI and two colliders that update it
Hi, i have the following problem. I have two colliders, each of them have the same script. The script increments a variable every time a collision is detected and displays it in a textUI. Every time the colliders alternate, the variable returns its value to zero and so de textUI. I need collisions to add up. Is it possible to do it in one script?
[RequireComponent(typeof(AudioSource))][RequireComponent(typeof(AudioSource))]
public class colision : MonoBehaviour {
public AudioClip sonidito;
AudioSource audio;
public Text contTxt;
private int cont;
void Start() {
audio = GetComponent<AudioSource>();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Esfera"))
{
Destroy(other.gameObject);
audio.PlayOneShot(sonidito, 0.7F);
cont++;
contTxt.text = "Cant: " + cont.ToString();
}
}
}
Comment
What happens if only one of the colliders uses this scripts?