void OnTriggerEnter(Collider collisionInfo) { if (collisionInfo.tag == "Interactable") { NPC_Script newDialog = collisionInfo.GetComponentInParent <NPC_Script>(); currentDialog = newDialog.Dialog; DialogCounter = 0; if (newDialog.triggerBattle) { triggerBattleFromDialog = true; } interactable = true; } else if (collisionInfo.tag == "ChangeScene") { ChangeScene newScene = collisionInfo.GetComponent <ChangeScene>(); gameController.MoveScene(newScene.SceneName, newScene.startingPosition, newScene.startingRotation); } else if (collisionInfo.tag == "Encounter") { encounter = true; } }
// 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 (cogAmmo >= 1) { Launch(); cogAmmo = cogAmmo - 1; SetCogAmmoText(); } else if (cogAmmo == 0) { } } 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) { NPC_Script character = hit.collider.GetComponent <NPC_Script>(); if (character != null) { character.DisplayDialog(); } } } if (Input.GetKey(KeyCode.R)) { if (gameOver == true) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); // this loads the currently active scene } } if (Input.GetKey("escape")) { Application.Quit(); } }