// Update is called once per frame void Update() { if (Lars.GetHeroHP() <= 0) // if lars's has no more HP the health will be destroyed { Destroy(gameObject); } DistanceX = Lars.GetLarsX(); DistanceZ = Lars.GetLarsZ(); transform.position = new Vector3(DistanceX, 3f, DistanceZ); // the heath bar is following lars transform.localScale = new Vector3(Lars.GetHeroHP() / 60F, 0.2F, 0.2F); // the health bar is scaled on the x axis according to lars's HP }
//This is the default Update() script - !!! public void AppleScriptUpdate() { //Look at lars this.transform.LookAt(GameObject.Find("Lars").transform); // the apples will always look at lars if (GUIScript.GetGameOn() == true) { DistanceX = Mathf.Abs(transform.position.x) - Mathf.Abs(Lars.GetLarsX()); // Calculates the distance on the x-axies of Lars and the apple by using the abselute value DistanceZ = Mathf.Abs(transform.position.z) - Mathf.Abs(Lars.GetLarsZ()); // Calculates the distance on the z-axies of Lars and the apple by using the abselute value // A range detector had to be made or the apples would always move if (Mathf.Abs(DistanceX - DistanceZ) <= 5.0f) // If the abselute value of the sum of Distance X and Z is smaller then 5 then: { InRange = true; // Lars is close enough and the apple should move towards him } else { InRange = false; // Lars is too far away and the apple shall stand still. } if (InRange == true) { if (DistanceX <= 5.0f && DistanceX >= 0.0f) // If Lars is standing far enough to the left then: { transform.position += new Vector3(-Speed, 0, 0) * Time.deltaTime; // Move the apple towards the left } else if (DistanceX <= 0.0f && DistanceX >= -5.0f) // If Lars is standing far enough to the right then: { transform.position += new Vector3(Speed, 0, 0) * Time.deltaTime; // Move the apple towards the right } if (DistanceZ <= 5.0f && DistanceZ >= 0.0f) // If Lars is standing far enough to the up then: { transform.position += new Vector3(0, 0, -Speed) * Time.deltaTime; // Move the apple towards the up } else if (DistanceZ <= 0.0f && DistanceZ >= -5.0f) // If Lars is standing far enough to the down then: { transform.position += new Vector3(0, 0, Speed) * Time.deltaTime; // Move the apple towards the down } } } }
// Update is called once per frame void Update() { if (GUIScript.GetGameOn() == true) { valueX = Mathf.Abs(Lars.GetLarsX() - transform.position.x); // x-axis distance from the tree and lars valueZ = Mathf.Abs(Lars.GetLarsZ() - transform.position.z); // z-axis distance from the tree and lars if (ATKready == true) { if (valueX < 2.0f && valueZ < 2.0f) { LarsOldX = Lars.GetLarsX(); // saves lars's current position LarsOldZ = Lars.GetLarsZ(); Invoke("damageFunction", 2); // will activate the damage function after 2 sec. ATKready = false; } else if (valueX < 4.0f && valueZ < 4.0f) { LarsOldX = Lars.GetLarsX(); // saves lars's current position LarsOldZ = Lars.GetLarsZ(); Invoke("damageFunction", 3); // will activate the damage function after 3 sec. ATKready = false; } else if (valueX < 6.0f && valueZ < 6.0f) { LarsOldX = Lars.GetLarsX(); // saves lars's current position LarsOldZ = Lars.GetLarsZ(); Invoke("damageFunction", 4); // will activate the damage function after 4 sec. ATKready = false; } else if (valueX < 8.0f && valueZ < 8.0f) { LarsOldX = Lars.GetLarsX(); // saves lars's current position LarsOldZ = Lars.GetLarsZ(); Invoke("damageFunction", 5); // will activate the damage function after 5 sec. ATKready = false; } else if (valueX < 10.0f && valueZ < 10.0f) { LarsOldX = Lars.GetLarsX(); // saves lars's current position LarsOldZ = Lars.GetLarsZ(); Invoke("damageFunction", 6); // will activate the damage function after 6 sec. ATKready = false; } } if (BossHP <= 0) // if the tree boss has no mor HP he will be destoyed { Destroy(gameObject); } // This code will set a small timer on 2 seconds or the attack would be very buggy if (ATKready == false) { ATKtimer++; if (ATKtimer == 12) { ATKready = true; ATKtimer = 0; } } } }