I want to switch animations when i click in a box. The idea is that when i click the box a animation start and after that the player need to get away of the box (OnColliderExit) and when the player interact again with the box clicking on it another animation starts.
The problem is that i made a counter to count the times the player clicks, and each time the OnColliderExit enter the counter increase.
BUT i have the problem that each time the player is OnColliderExit the counter increase 2 numbers, and i need that only increase one. I dont know if is something on the code or with the colliders.
If someone did this kid of interactions im open to other ways to do it .
The code:
private void OnTriggerStay(Collider other){
if (Input.GetMouseButtonDown(0)){
tapa.enabled = true;
tapa.Play("caja_izq_abriendo");
switch (contador) {
case 0:
if (other == desencadenante && Condicion == estado.TriggerStay)
{
objetivo_uno.enabled = true;
objetivo_uno.Play("luzes_point_c");
source_uno.clip = track_uno;
source_uno.Play();
}
break;
case 1:
if (other == desencadenante && Condicion == estado.TriggerStay)
{
objetivo_dos.enabled = true;
objetivo_dos.Play("perlins");
source_dos.clip = track_dos;
source_dos.Play();
}
break;
case 2:
if (other == desencadenante && Condicion == estado.TriggerEnter)
{
objetivo_dos.enabled = true;
objetivo_dos.Play("cilindros_arriba");
source_tres.clip = track_tres;
source_tres.Play();
}
break;
}
}
}
private void OnTriggerEnter(Collider other)
{
clic.enabled = true;
clic.Play("clic_1");
Debug.Log(contador);
}
private void OnTriggerExit(Collider other)
{
clic.enabled = true;
clic.Play("clic_exit");
contador++;
Debug.Log(contador);
if (contador >= 3) {
contador = 0;
}
}