// Update is called once per frame void Update() { coinText.GetComponent <Text>().text = "" + currentCoin.ToString() + "/5"; if (Input.GetKey("escape")) { Application.Quit(); } IEnumerator Reset(float Count) { yield return(new WaitForSeconds(Count)); yield return(null); } if (health <= 0) { //PlaySound(dieSound); Invoke("Restart", 3.0f); } 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.N)) { SceneManager.LoadScene("RubyFinal2"); } if ((Input.GetKeyDown(KeyCode.C) && currentAmmo > 0)) { Launch(); currentAmmo -= 1; } ammoText.GetComponent <Text>().text = currentAmmo.ToString(); ///// if ((Input.GetKeyDown(KeyCode.D) && currentRedAmmo > 0)) { Launch2(); currentRedAmmo -= 1; } ammoRedText.GetComponent <Text>().text = currentRedAmmo.ToString(); ////// 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) { character.DisplayDialog(); } } } // if (Input.GetKeyDown(KeyCode.X)) { RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC2")); if (hit.collider != null) { NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>(); if (character != null) { character.DisplayDialog(); } } } // 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) { Debug.Log(RobotsFixed.instance.robotsFixed); if ((RobotsFixed.instance.robotsFixed == 6 && currentCoin == 5)) { character.DisplayDialog2(); StartCoroutine(WaitForSec()); } IEnumerator WaitForSec() { yield return(new WaitForSeconds(4)); SceneManager.LoadScene("RubyFinal2"); } } } } // if (Input.GetKeyDown(KeyCode.X)) { RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC2")); if (hit.collider != null) { NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>(); if (character != null) { Debug.Log(RobotsFixed.instance.robotsFixed); if ((RobotsFixed.instance.robotsFixed == 6 && currentCoin >= 5)) { character.DisplayDialog2(); audioSource.Play(); speed = 0; } } } } // if (Input.GetKeyDown(KeyCode.X)) { RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("Cube")); if (hit.collider != null) { ResourceCube rc = hit.collider.GetComponent <ResourceCube>(); if (rc != null) { PlaySound(findSound); rc.BlownUp(); } } } }
// 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)) { Launch(); } // Raycasting if (Input.GetKeyDown(KeyCode.X)) { RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC")); RaycastHit2D box = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("BOX")); if (hit.collider != null) { NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter> (); if (character != null) { character.DisplayDialog(); } } if (box.collider != null) { ResourceCube boxObject = box.collider.GetComponent <ResourceCube> (); if (boxObject != null) { boxObject.spawnPrefabs(); } } } // Winning if (robotCount == 5 && SceneManager.GetActiveScene().buildIndex == 1) { backgroundNoise.SetActive(false); winNoise.SetActive(true); rigidbody2d.simulated = false; } // Death/Game Over if (currentHealth <= 0) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } }
// Update is called once per frame void Update() { EnemyCount count = fixTracker.gameObject.GetComponent <EnemyCount>(); if (count.fixCount == count.fixRequired && canPlay == true) { PlaySound(victory); canPlay = false; } horizontal = Input.GetAxis("Horizontal"); vertical = Input.GetAxis("Vertical"); if (Input.GetKeyDown(KeyCode.X) || Input.GetButtonDown("Fire1")) { //RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.zero * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC")); RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.down * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC")); if (hit.collider != null) { Debug.Log("Raycast has hit the object " + hit.collider.gameObject); NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>(); if (character != null) { character.DisplayDialog(); } else { //ResourceCube(); ResourceCube cube = hit.collider.GetComponent <ResourceCube>(); cube.GetResources(); Destroy(hit.collider.gameObject); } } } //if(Input.GetKeyDown(KeyCode.C) && ammo > 0) //{ // Launch(); // PlaySound(throwSound); //} if (Input.GetButtonDown("Fire3") && ammo > 0) { Launch(); PlaySound(throwSound); } 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 (currentHealth <= 0) { SceneManager.LoadScene(currentScene.name); } }