public override void Act(GameObject player, GameObject npc) { // get battleship BattleshipBoss battleship = npc.GetComponent <BattleshipBoss>(); if (battleship) { // Use weapons if (Time.time >= battleship.NextFireTime) { // Set cooldown float cooldown = 3.5f; battleship.NextFireTime = Time.time + cooldown; // Center sphere battleship.weapons[0].fire(); // Center bubbles battleship.weapons[1].fire(); // Side bolts battleship.StartCoroutine(battleship.delayAimFire(battleship.weapons[4], player, 0.5f)); battleship.StartCoroutine(battleship.delayAimFire(battleship.weapons[5], player, 1.0f)); // Side spheres battleship.StartCoroutine(battleship.delayAimFire(battleship.weapons[2], player, 2.0f)); battleship.StartCoroutine(battleship.delayAimFire(battleship.weapons[3], player, 2.5f)); } } else { Debug.LogWarning("This state can only handle Battleship."); } }
public override void Act(GameObject player, GameObject npc) { // get battleship Battleship = npc.GetComponent <BattleshipBoss>(); if (Battleship) { // Move to the position Vector3 pos = npc.transform.position; if (pos.z > Battleship.ZMin) { float speed = Battleship.verticalSpeed; npc.transform.position += speed * Time.deltaTime * npc.transform.forward; } // Randomly move right or left if (Time.time >= Battleship.NextMoveTime) { // Set next move time float duration = Random.Range(0.5f, 2.0f); Battleship.NextMoveTime = Time.time + duration; // X-axis speed Rigidbody rigidbody = npc.GetComponent <Rigidbody>(); float sign = -Mathf.Sign(pos.x); rigidbody.velocity = new Vector3(sign * Battleship.horizontalSpeed, 0.0f, rigidbody.velocity.z); } // Use weapons if (Time.time >= Battleship.NextFireTime) { // Set cooldown float cooldown = 3.5f; Battleship.NextFireTime = Time.time + cooldown; // Center bubbles Battleship.weapons[1].fire(); // Side bolts Battleship.StartCoroutine(Battleship.delayAimFire(Battleship.weapons[4], player, 1.0f)); Battleship.StartCoroutine(Battleship.delayAimFire(Battleship.weapons[5], player, 1.0f)); } } else { Debug.LogWarning("This state can only handle Battleship."); } }