Exemple #1
0
 public void Explode(Dieable dieable)
 {
     Collider2D[] cols = Physics2D.OverlapCircleAll(transform.position, damageRadius);
     foreach (var col in cols)
     {
         Rigidbody2D rb = col.GetComponent <Rigidbody2D>();
         if (rb == null)
         {
             continue;
         }
         Dieable lel = rb.GetComponent <Dieable>();
         if (lel == dieable)
         {
             continue;
         }
         Vector3 displacement = rb.transform.position - transform.position;
         rb.AddForce(displacement.normalized * knockback, ForceMode2D.Impulse);
         HasHealth health = rb.GetComponent <HasHealth>();
         if (health != null)
         {
             if (col.tag == "Player")
             {
                 health.Damage(damagePlayer);
             }
             else if (col.tag == "Enemy" && !col.gameObject.GetComponent <Enemy>().isDead)
             {
                 health.Damage(damageEnemy);
             }
         }
     }
     sRenderer.color = Color.white;
     timer.StartTimer(fadeoutTime);
     exploded = true;
 }
Exemple #2
0
 private void OnCollisionStay2D(Collision2D collision)
 {
     if (collision.gameObject.layer == LayerMask.NameToLayer("Entities"))
     {
         HasHealth hasHealth = collision.gameObject.GetComponent <HasHealth>();
         if (hasHealth != null)
         {
             hasHealth.Damage(Damage);
         }
     }
 }
Exemple #3
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject obj = collision.gameObject;

        if (obj.tag == "Bullet" && obj.tag != "Wall")
        {
            return;
        }


        if (obj.tag == "Wall" || (Time.time - lastHit > safeTime && IsFatal()))
        {
            HasHealth health = obj.GetComponent <HasHealth>();
            if (health != null && Damages(obj.tag))
            {
                health.Damage(damage);
            }
            Destroy(gameObject);
        }
        lastHit = Time.deltaTime;
    }