//On collision public override void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider) { //Attempt to match other object as a wall WallGameObject wall = otherCollisionHandler as WallGameObject; //Attempt to match other object as a wall BulletGameObject bullet = otherCollisionHandler as BulletGameObject; //If the other object is a wall if (wall != null) { //Get collider BoxCollider wallBoxCollider = otherCollider as BoxCollider; //Move out of it's range GameObjectHelper.resolveRectangularCollision(this, wallBoxCollider); //Choose another action PickRandomAction(); } //If the other object is a bullet if (bullet != null) { //If the other object is a player bullet if (bullet.Name == "player_bullet") { //Destroy the bullet bullet.Destroy(); //Destroy this object Destroy(); } } }
//Registers a new collider with an event handler public void registerCollider(ICollider collider, ICollisionEventHandler collisionHandler) { //Create a new registered collider RegisteredCollider newRegisteredCollider = new RegisteredCollider(); newRegisteredCollider.collider = collider; newRegisteredCollider.collisionHandler = collisionHandler; //Add the new collider to the index colliders.Add(newRegisteredCollider); }
//On collision with a game object public override void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider) { //Attempt to match other object as a wall WallGameObject wall = otherCollisionHandler as WallGameObject; //If the other object is a wall if (wall != null) { //Destroy this bullet Destroy(); } }
//When a collision occurs public override void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider) { //Attempt to match other object as a wall WallGameObject wall = otherCollisionHandler as WallGameObject; //If other object is a wall if (wall != null) { //Get collider BoxCollider wallBoxCollider = otherCollider as BoxCollider; //Move out of it's range GameObjectHelper.resolveRectangularCollision(this, wallBoxCollider); } }
//On collision public override void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider) { //Attempt to match other object as a wall WallGameObject wall = otherCollisionHandler as WallGameObject; //Attempt to match other object as a wall BulletGameObject bullet = otherCollisionHandler as BulletGameObject; //Attempt to match other object as an enemy EnemyGameObject enemy = otherCollisionHandler as EnemyGameObject; //If the other object is a wall if (wall != null) { //Get collider BoxCollider wallBoxCollider = otherCollider as BoxCollider; //Move out of it's range GameObjectHelper.resolveRectangularCollision(this, wallBoxCollider); } //If the other object is a bullet if (bullet != null) { //If the other object is an enemy bullet if (bullet.Name == "enemy_bullet") { //Destroy the bullet bullet.Destroy(); //Destroy this object Destroy(); } } //If the other object is an enemy if (enemy != null) { //If the other object is an enemy bullet if (enemy.Name == "enemy") { //Destroy this object Destroy(); } } }
//On collision with a game object public override void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider) { }
//Triggered upon a collision event abstract public void OnCollision(ICollisionEventHandler otherCollisionHandler, ICollider otherCollider);