// when hit by a bullet void OnTriggerEnter2D(Collider2D col) { BulletScript bullet = col.GetComponent <BulletScript>(); if (bullet != null) { GetsHit(bullet.GetDamage()); Destroy(col.gameObject); } }
private void OnTriggerEnter2D(Collider2D collision) { BulletScript bullet = collision.gameObject.GetComponent <BulletScript>(); targetHealth -= bullet.GetDamage(); if (targetHealth <= 0) { Destroy(gameObject); } bullet.Hit(); }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.GetComponent <Mortal>() == null && col.gameObject.GetComponent <BulletScript>() == null) { return; } switch (col.gameObject.tag) { case GameManager.UnitTag: if (col.gameObject.GetComponent <Mortal>().team != teamNum) { col.gameObject.GetComponent <Mortal>().TakeDamage(energy); this.Destroy(); } else { Physics2D.IgnoreCollision(GetComponent <Collider2D>(), col.collider); } break; case GameManager.StatueTag: if (col.gameObject.GetComponent <Mortal>().team != teamNum) { col.gameObject.GetComponent <Mortal>().TakeDamage(energy); this.Destroy(); } break; case "Bad": BulletScript bul = col.gameObject.GetComponent <BulletScript>(); if (!idSeen.Contains(bul.id)) { if (bul.teamNum != teamNum) { float oldDmg = bul.GetDamage(); bul.TakeDamage(energy); this.TakeDamage(oldDmg); } bul.idSeen.Add(id); } Physics2D.IgnoreCollision(GetComponent <Collider2D>(), col.collider); break; default: this.Destroy(); break; } }
public override void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { PlayerScript player = other.gameObject.GetComponent <PlayerScript>(); player.TakeDamage(damage); } else if (other.gameObject.tag == "PlayerProjectile") { BulletScript bullet = other.gameObject.GetComponent <BulletScript>(); Debug.Log("Bat Hitted by projektile"); Debug.Log("Bullet damage = " + damage); TakeDamage(bullet.GetDamage()); Destroy(bullet.gameObject); } }
public virtual void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { PlayerScript player = other.gameObject.GetComponent <PlayerScript>(); player.TakeDamage(damage); if (isProjectile) { Die(); } } if (other.gameObject.tag == "PlayerProjectile") { BulletScript bullet = other.gameObject.GetComponent <BulletScript>(); TakeDamage(bullet.GetDamage()); Destroy(bullet.gameObject); } }