override public void Fire(SpaceshipEnemy entity, GameObject weapon) { GameObject weaponObj = Object.Instantiate(weapon, entity.transform.position, entity.transform.rotation); weaponObj.layer = 8; Weapon weaponComponent = weaponObj.GetComponent <Weapon> (); weaponComponent.direction = -entity.transform.up; weaponComponent.SetUser(entity.gameObject); }
override public void Move(SpaceshipEnemy entity) { float elapsedTime = Time.deltaTime; Vector3 playerDir = player.transform.position - entity.transform.position; float angle = Vector3.Angle(entity.transform.forward, playerDir); Vector3 cross = Vector3.Cross(entity.transform.forward, playerDir); if (cross.y < 0) { angle *= -1; } entity.transform.Rotate(angle * elapsedTime * entity._rotationSpeed, 0, 0); entity.transform.Translate(0, 0, elapsedTime * entity._speed); }
private void OnTriggerEnter(Collider other) { //Debug.Log( "TriggerEnter: " +this.name +" hit " +other.name ); // Find the types that are colliding. bool isThisPlayer = this is SpaceshipPlayer; SpaceshipEnemy enemyShip = other.gameObject.GetComponent <SpaceshipEnemy>(); // Check if this is an enemy ship colliding with another enemy ship. If so, ignore the collision. if (this is SpaceshipEnemy == true && enemyShip != null) { return; } // Check to see if this ship is colliding with a bullet. Bullet bullet = other.gameObject.GetComponent <Bullet>(); if (bullet != null) { if (this.HitByBullet(bullet) == true) { // The bullet hit the ship. Bullet no longer needed so can be destroyed here. Destroy(bullet.gameObject); } // Nothing else to do with the bullet. return; } // Check if this is a player ship colliding with an enemy ship then destroy both ships. if (isThisPlayer == true && enemyShip != null) { // Destroy the enemy ship. enemyShip.DestroySoundAndParticles(); enemyShip.DestroyShip(); // Destroy the player ship. this.DestroySoundAndParticles(); this.DestroyShip(); } }
static public GameObject Spawn(GameObject parent, Vector3 position, Quaternion rotation, int speed = -1, int life = -1, int pointsValue = -1) { GameObject spac = Instantiate(parent, position, rotation); SpaceshipEnemy ctrl = spac.GetComponent <SpaceshipEnemy> (); if (speed != -1) { ctrl._speed = speed / 100.0f; } if (life != -1) { ctrl._life = life; } if (pointsValue != -1) { ctrl._pointsValue = pointsValue; } return(spac); }
override public void Move(SpaceshipEnemy entity) { float elapsedTime = Time.deltaTime; _turnTimer -= elapsedTime; if (_turnTimer <= 0) { moveChoice = Random.Range(0, 101); _turnTimer = _turnTime; } if (moveChoice < 37) { entity.transform.Rotate(new Vector3(0, 0, entity._rotationSpeed * elapsedTime)); } else if (moveChoice < 76) { entity.transform.Rotate(new Vector3(0, 0, -entity._rotationSpeed * elapsedTime)); } entity.transform.Translate(elapsedTime * entity._speed, 0, 0); }
public abstract void UpdateFireDirection(SpaceshipEnemy entity);
override public void UpdateFireDirection(SpaceshipEnemy entity) { entity.fireDirection = -entity.transform.up; }
public abstract void Fire(SpaceshipEnemy entity, GameObject weapon);
public abstract void Move(SpaceshipEnemy entity);
override public void UpdateFireDirection(SpaceshipEnemy entity) { }
override public void Fire(SpaceshipEnemy entity, GameObject weapon) { }
override public void UpdateFireDirection(SpaceshipEnemy entity) { entity.fireDirection = player.transform.position - entity.transform.position; }