void Update() { // game stops and shows leaderboard if (GameTimer <= 0) { board.SetActive(true); Time.timeScale = 0F; Endgame(); } // runs kill and end game script to input kills and death values //Endgame(); healthBar = GameObject.Find("OsledShip(Clone)/PirateShip(Clone)/Canvas/Health").GetComponent <shiphealth>(); healthBar1 = GameObject.Find("PataShip(Clone)/PirateShip(Clone)/Canvas/Health").GetComponent <shiphealth>(); healthBar2 = GameObject.Find("JeroenShip(Clone)/PirateShip(Clone)/Canvas/Health").GetComponent <shiphealth>(); // gets the health of the AIs Osledhealth = healthBar.health; Patahealth = healthBar1.health; Jeroenhealth = healthBar2.health; // checks the AIs health and respawn on death and reset their health and cannons if (Osledhealth <= 0) { int I = Random.Range(0, 3); Debug.Log("f**k i respawned with now caps" + "ahha"); GameObject.Find("OsledShip(Clone)").transform.position = SpawnPoints[I].transform.position; OsledDeath += 1; healthBar.health = 100; healthBar.SetHealth(100); } if (Patahealth <= 0) { int I = Random.Range(0, 3); GameObject.Find("PataShip(Clone)").transform.position = SpawnPoints[I].transform.position; PataDeath += 1; healthBar1.health = 100; healthBar1.SetHealth(100); } if (Jeroenhealth <= 0) { JeroenDeath += 1; int I = Random.Range(0, 3); GameObject.Find("JeroenShip(Clone)").transform.position = SpawnPoints[I].transform.position; healthBar2.health = 100; healthBar2.SetHealth(100); } }
void FixedUpdate() { agent.updateRotation = true; currentRotation = transform.rotation.y; //currentPosition = transform.position.z; approach[0] = GameObject.Find("OsledShip(Clone)").transform; approach[1] = GameObject.Find("JeroenShip(Clone)").transform; health = GameObject.Find("PataShip(Clone)/PirateShip(Clone)/Canvas/Health").GetComponent <shiphealth>(); // timer for reloading if (shotFired == true && reload > 0f) { reload -= Time.fixedDeltaTime; } else if (reload < 0f) { shotFired = false; reload = 5f; } // timer for Idle position if (resetIdle == true && loopIdle > 0f) { loopIdle -= Time.fixedDeltaTime; } else if (loopIdle < 0f) { resetIdle = false; loopIdle = 3f; } //quick check if (moreAmmo != null) { moreAmmo = GameObject.FindWithTag("Ammo"); } if (moreHealth != null) { moreHealth = GameObject.FindWithTag("Health"); } // defense if (cannonBallAmount <= 5 && moreAmmo != null) { agent.SetDestination(moreAmmo.transform.position); Debug.Log("PATA getting ammo"); } else if (currentHeath <= 20 && moreHealth != null) { agent.SetDestination(moreHealth.transform.position); Debug.Log("PATA getting health"); } StartCoroutine(__Idle()); StartCoroutine(__Attack()); StartCoroutine(__RunAway()); if (currentHeath > 100) { currentHeath = 100; } }