Search Unity

Wrong working trigger

Discussion in 'Editor & General Support' started by gromilQaaaa, Dec 4, 2013.

  1. gromilQaaaa

    gromilQaaaa

    Joined:
    Oct 28, 2013
    Posts:
    14
    $rabbit_trigger.jpg
    I got gameObject called "Rabbit" that has 2 empty objects with box_colliders-triggers inside. (Image attached)

    Both empty objects have c# scripts attached that make counting like this:

    Code (csharp):
    1. public class Power_Megajump_trigger : MonoBehaviour {
    2.     public GameObject Rabbit;
    3.    
    4.     private int counter_megajump = 0;
    5.     // Use this for initialization
    6.     void Start ()
    7.     {
    8.        
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update ()
    13.     {
    14.         if (counter_megajump >= 3)
    15.         {
    16.             Rabbit.GetComponent<Rabbit_Powers>().MegaJump();
    17.         }
    18.     }
    19.    
    20.     void OnTriggerEnter2D (Collider2D col)
    21.     {
    22.         // If it hits an enemy...
    23.         if(col.tag == "Enemy")
    24.         {
    25.             counter_megajump++;
    26.             Debug.Log (counter_megajump + " enemys in jump zone");
    27.         }
    28.     }
    29.    
    30.     void OnTriggerExit2D (Collider2D col)
    31.     {
    32.         // If it hits an enemy...
    33.         if(col.tag == "Enemy")
    34.         {
    35.             counter_megajump--;
    36.             Debug.Log (counter_megajump + " enemys in jump zone");
    37.         }
    38.     }
    39. }
    Enemy's die like this:
    Code (csharp):
    1.     void Death()
    2.     {
    3.         Debug.Log("Enemy Killed");
    4.         gameObject.transform.Translate (Vector3.up * 10000);
    5.         Destroy (gameObject,0.001f);
    6.         isDead = true;
    7.     }
    Here's the problem:
    Stomp_trigger counts normally.
    Megajump_trigger in a few enters starts to count -1, -2, -3...

    How can I fix that, or maybe you can advise me another way to get information about how many enemys are standing in some zone?
     
unityunity