Search Unity

problem with OnTriggerEnter ....

Discussion in 'Scripting' started by wisien92, May 7, 2014.

  1. wisien92

    wisien92

    Joined:
    Nov 16, 2012
    Posts:
    56
    I have set up a light and give it a child that is a SphereCollider with isTrigger true. I can enable the light(and with it the child) and it's automaticly disabled. When i use OnTriggerEnter it gives me nothing .....

    here is the code (i even set a cube with tag "Enemy" and still nothing .... dunno what i do wrong)

    Code (csharp):
    1.  
    2.     void OnTriggerEnter(Collider other) {
    3.         Debug.Log(other.tag);
    4.  
    5.         if (other.tag == "Enemy") {
    6.             Debug.Log("Enemy Blinded!");
    7.         }
    8.     }
    9.  


    one more question .... when this 2nd code hits the enemy it works but only once .... the second time not .... dunno why
    Code (csharp):
    1.  
    2. Collider[] colliders = Physics.OverlapSphere(soundPosition, radius);
    3.  
    4.     foreach (Collider hit in colliders) {
    5.        if (hit  hit.tag == "Enemy") {
    6.         Debug.Log("Enemy can hear you");                   
    7.         }
    8.     }
    9.  
     
    Last edited: May 7, 2014
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Rigidbodies ? You may need them
     
  3. wisien92

    wisien92

    Joined:
    Nov 16, 2012
    Posts:
    56
    hmm i don't have them but i will try with it

    EDIT: nope adding rigidbody to the enemy did nothing

    EDIT2: When i give ontriggerenter to a static trigger and enterit it works but again ... only once

    EDIT3: I had collapse in console widnow .... lol :D
     
    Last edited: May 8, 2014