// Update is called once per frame void Update() { horizontal = Input.GetAxis("Horizontal"); vertical = Input.GetAxis("Vertical"); Vector2 move = new Vector2(horizontal, vertical); if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) { lookDirection.Set(move.x, move.y); lookDirection.Normalize(); } animator.SetFloat("Look X", lookDirection.x); animator.SetFloat("Look Y", lookDirection.y); animator.SetFloat("Speed", move.magnitude); if (isInvincible) { invincibleTimer -= Time.deltaTime; if (invincibleTimer < 0) { isInvincible = false; } } if (Input.GetKeyDown(KeyCode.C)) { if (cogs > 0) { Launch(); } } if (Input.GetKeyDown(KeyCode.X)) { RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC")); if (hit.collider != null) { NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>(); if (character != null) { if (currentScore >= 4) { character.DisplayDialogNextLevel(); UnityEngine.SceneManagement.SceneManager.LoadScene(1); level = 2; } else { character.DisplayDialog(); } } } } // win condition if (currentScore >= 4) { gameOver = true; // staticVar = true; if (Input.GetKey(KeyCode.R)) { if (gameOver == true) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } } } if (health <= 0) { PlaySound(musicClipThree); speed = 0.0f; gameOver = true; if (Input.GetKey(KeyCode.R)) { if (gameOver == true) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); // this loads the currently active } } } if (Input.GetKeyDown(KeyCode.Q)) { musicSource.clip = musicClipThree; musicSource.Play(); gameOverText.text = "Alt Music 2 (Lose song)"; } else if (Input.GetKeyUp(KeyCode.Q)) { musicSource.clip = musicClipOne; musicSource.Play(); gameOverText.text = ""; } if (Input.GetKey("escape")) { Application.Quit(); } }