// Update is called once per frame void Update() { if (GUIScript.GetGameOn() == true) { LarsX = transform.position.x; // Gets Larses current X coordinates LarsZ = transform.position.z; // Gets Larses current Z coordinate // The following code will make our character move with the a,w,d,s or arrow keys and make him face in that direction if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { transform.position += new Vector3(-3.0f, 0, 0) * Time.deltaTime; transform.eulerAngles = new Vector3(0, 270, 0); } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { transform.position += new Vector3(3.0f, 0, 0) * Time.deltaTime; transform.eulerAngles = new Vector3(0, 90, 0); } if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { transform.position += new Vector3(0, 0, 3f) * Time.deltaTime; transform.eulerAngles = new Vector3(0, 0, 0); } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { transform.position += new Vector3(0, 0, -3f) * Time.deltaTime; transform.eulerAngles = new Vector3(0, 180, 0); } // This statement will make Lars shot a ball of fire if (Input.GetKeyDown(KeyCode.Space) && BallIsReady == true) { Instantiate(Spawn, transform.position + transform.forward, Quaternion.identity); BallIsReady = false; } // This following code will make a timer for the cooldown for when Lars can fire another ball of fire (so he can't spam them) if (BallIsReady == false) { BallCoolDown--; // When a ball of fire have been fired off will this variable cound down each frame until it reaches 0 if (BallCoolDown == 0) { BallIsReady = true; // A new ball can then be fired again BallCoolDown = 48; // And the timer resets to 2 seconds } } // Lars shall not be able to stack too much HP, this will set the cap so he can't reach over his maximum HP if (HeroHP > MaxHP) { HeroHP = MaxHP; } // If Lars's HP becomes 0 or below then will he be destroyed if (HeroHP <= 0) { Destroy(gameObject); } } }
void OnGUI() { // This one will show the number of apple seeds the player have collected if (GUIScript.GetGameOn() == true) { GUI.Label(new Rect(40, 80, 200, 100), "<size=40>" + Lars.GetPoints() + "</size>"); } if (GUI.Button(new Rect(10, 10, 100, 50), "Quit")) { Application.Quit(); } }
// Update is called once per frame void Update() { if (GUIScript.GetGameOn() == true) { AppleSeed.enabled = true; // When the game starts will the apple seed image be shown } if (Lars.GetHeroHP() <= 0) { Lose.enabled = true; // If Lars's HP gets to 0 or below will the lose screen pop up } else if (tree.GetBossHP() <= 0) { Win.enabled = true; // If the Tree's HP gets to 0 or below will the win screen pop up } }
//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; } } } }