void OnCollisionEnter2D(Collision2D collision) { // When we collide with an object, check its components. // Then add it to the appropriate lists. PlayerController pc = collision.gameObject.GetComponent <PlayerController>(); BulletMotor bm = collision.gameObject.GetComponent <BulletMotor>(); Rigidbody2D rb = collision.gameObject.GetComponent <Rigidbody2D>(); if (pc != null) { BaseOnPlayerCollision(pc); } if (bm != null) { BaseOnBulletCollision(bm); } if (rb != null) { BaseOnRigidbodyCollision(rb); } }
void OnCollisionExit2D(Collision2D collision) { // When we stop colliding with an object, check its components. // Then remove it from the appropriate lists. PlayerController pc = collision.gameObject.GetComponent <PlayerController>(); BulletMotor bm = collision.gameObject.GetComponent <BulletMotor>(); Rigidbody2D rb = collision.gameObject.GetComponent <Rigidbody2D>(); if (pc != null) { BaseOnPlayerExit(pc); } if (bm != null) { BaseOnBulletExit(bm); } if (rb != null) { BaseOnRigidbodyExit(rb); } }
void BulletWasCollided(BulletMotor bullet) { SpaceShipMotor playerShip = gm.playerShip; if (bullet.sourceShip == playerShip && this != playerShip) { DamageShip (bullet.damage, DamageSource.Player); bullet.BulletCatched (); } else if (bullet.sourceShip != playerShip && this == playerShip) { DamageShip (bullet.damage, DamageSource.Player); bullet.BulletCatched (); } }
protected virtual void OnBulletExit(BulletMotor bullet) { }
protected virtual void BulletUpdate(BulletMotor bullet) { }
protected virtual void OnBulletCollision(BulletMotor bullet) { }
void BaseOnBulletExit(BulletMotor bullet) { collidingBullets.Remove(bullet); OnBulletExit(bullet); }
void BaseOnBulletCollision(BulletMotor bullet) { collidingBullets.Add(bullet); OnBulletCollision(bullet); }