void Update() { //aims towards player. if (this.playerShip != null) { this.RepairShip(); Vector3 targetPos = Camera.main.WorldToScreenPoint(playerShip.transform.position); Vector3 selfPos = Camera.main.WorldToScreenPoint(this.transform.position); selfPos.x = selfPos.x - targetPos.x; selfPos.y = selfPos.y - targetPos.y; float angle = Mathf.Atan2(selfPos.y, selfPos.x) * Mathf.Rad2Deg; this.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle - 270)); // Moves towards player. this.transform.Translate(0, 0.01f * enemyShipSpeed, 0, Space.Self); bool outer = targetRadar.RadarPing(); bool inner = radar.RadarPing(); // Spawns units. fanaticSpawner.Spawn(); carrierSubSpawner.Spawn(); // If player is either too far or too close fires weapons towards player. if (outer == false) { doomLaser.Shoot(); } if (inner == true) { laser1.Shoot(); laser2.Shoot(); } } }
void Update() { if (this.playerShip != null) { this.RepairShip(); //aims towards player. Vector3 targetPos = Camera.main.WorldToScreenPoint(playerShip.transform.position); Vector3 selfPos = Camera.main.WorldToScreenPoint(this.transform.position); selfPos.x = selfPos.x - targetPos.x; selfPos.y = selfPos.y - targetPos.y; float angle = Mathf.Atan2(selfPos.y, selfPos.x) * Mathf.Rad2Deg; //Moves towards player this.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle - 270)); this.transform.Translate(0, 0.01f * enemyShipSpeed, 0, Space.Self); // When player is in TargetRadars range fires weapons. bool targetInSight = targetRadar.RadarPing(); if (targetInSight == true) { laser1.Shoot(); doomLaser.Shoot(); laser2.Shoot(); missileLauncher1.rocket(); missileLauncher2.rocket(); } } }