public void IgnoreCollider(Collider2D col)
 {
     Physics2D.IgnoreCollision(collider2D,col);
     if(ignored == null) {
         ignored = new List<Collider2D>();
     }
     ignored.Add(col);
     //ignore each child collider as well
     Collider2D[] childCols = col.GetComponentsInChildren<Collider2D>();
     foreach(Collider2D childCol in childCols) {
         Physics2D.IgnoreCollision(collider2D,childCol);
         ignored.Add (childCol);
     }
 }
Example #2
0
    void OnTriggerStay2D(Collider2D collider)
    {
        Damageable damageable = collider.GetComponent<Damageable>();
        if (damageable) {
            damageable.TakeDamage (damagePerSecond * Time.deltaTime, gameObject, new Vector2(0,0));
        }

        if (Random.Range (0, 1) < Time.deltaTime) {
            BodyPart[] bodyParts = collider.GetComponentsInChildren<BodyPart> ();
            if(bodyParts.Length > 0) {
                BodyPart bodyPart = bodyParts[Random.Range (0, bodyParts.Length)];
                GameObject fire = Instantiate(firePrefab, bodyPart.transform.position, Quaternion.identity) as GameObject;
                fire.transform.SetParent(bodyPart.transform);
                Destroy (fire, 3);
            }
        }
    }