CollisionEnter issue

When I enter collision, if it’s not to destroy the object (such as consumable itens), it does lots of events if I keep pressing to that direction. How to fix this? I thought of making the char glow red and get invincible for a few secs, but how to do that? And I always have problem using that WaitForSeconds in C#.

Thanks

Hi,

If I understand correctly you want to trigger event just once, even do you are inside the trigger object.
If this is the case you should make Boolean variable, set it initially to false, and in the if statement check if that var is false (in trigger event) and inside the if statement make you code (make player invincible) and SET THAT VAR TO TRUE!
This will make trigger event execute only once.
Then you could use Collider.OnTriggerExit event to return that var to false, to be ready for next OntriggerEnter event.

Regards.

I could try that, but I have a Controller in my character and I check through OnControllerColliderHit, is there an exit for this?

The code: using UnityEngine; using System.Collections;

public class PersonagemCol : MonoBehaviour { private void OnControllerColliderHit(ControllerColliderHit hit) { switch (hit.collider.name) { case "jarro": { Destroy(hit.transform.GetChild(1).gameObject); hit.collider.name = "jarroVazio"; break; }

            case "heart":
                {
                    PersonagemHealth another = (PersonagemHealth)this.GetComponent(typeof(PersonagemHealth));
                    another.AjustarVida(10);
                    Destroy(hit.gameObject);
                    break;
                }

            case "apple":
                {
                    Dinheiro another = (Dinheiro)hit.collider.GetComponent(typeof(Dinheiro));
                    another.AjustarFrutas();
                    Destroy(hit.gameObject);
                    break;
                }
        }

            //Somente inimigos
                switch(hit.collider.name)
                {
                    case "Turtle":
                        {
                        PersonagemHealth another = (PersonagemHealth)this.GetComponent(typeof(PersonagemHealth));
                        another.AjustarVida(-10);
                        break;
                        }

                    case "Spider":
                        {
                        PersonagemHealth another = (PersonagemHealth)this.GetComponent(typeof(PersonagemHealth));
                        another.AjustarVida(-15);
                        break;
                        }
                }
            }
        }

It doesn’t matter. You can use OnTrigger events as well.