//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(); } } }
//When the attack button is pressed public void Attack() { //Create a new bullet BulletGameObject newBullet = new BulletGameObject(Position, Container, 1000.0, 300); newBullet.Name = "player_bullet"; newBullet.SetDirection(Direction); //Register the bullet Container.registerGameObject(newBullet); }
//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(); } } }