// Update is called once per frame private void Update() { if (SceneManager.GetActiveScene().name == "Battle") { if (firstUpdate) { UpdateHealthBar(); UpdateManaBar(); firstUpdate = false; } if (Input.GetKeyDown(KeyCode.Space) && FindObjectOfType <UI_Assistant>().InDialogue()) { bool endOfDialogue = GameObject.Find("UI_Assistant").GetComponent <UI_Assistant>().DisplayNextSentence(); if (endOfDialogue) { FindObjectOfType <BeatKeeper>().SetRunning(true); } } else { string action = null; if (Input.GetKeyDown(KeyCode.D)) { action = "Attacking"; } else if (Input.GetKeyDown(KeyCode.W)) { action = "Charging"; } else if (Input.GetKeyDown(KeyCode.S)) { action = "Blocking"; } else if (Input.GetKeyDown(KeyCode.A)) { action = "Healing"; } if (action != null && FindObjectOfType <BeatKeeper>().HitBeat()) { animator.SetBool(action, true); state = action; } } } else // in overworld { // Get directional input int horizontal = 0; int vertical = 0; horizontal = (int)Input.GetAxisRaw("Horizontal"); vertical = (int)Input.GetAxisRaw("Vertical"); if (vertical != 0) { horizontal = 0; } //interact with object in game if (Input.GetKeyDown(KeyCode.Space) && currentInterObj != null) { Debug.Log(currentInterObj.name); if (FindObjectOfType <UI_Assistant>().InDialogue()) { bool endOfDialogue = GameObject.Find("UI_Assistant").GetComponent <UI_Assistant>().DisplayNextSentence(); if (endOfDialogue && currentInterObjScript.IsItem()) { inventory.AddItem(currentInterObjScript.GetItem()); Destroy(currentInterObj); } } else { if (currentInterObjScript.NeedsItem() && inventory.HasItem(currentInterObjScript.NeededItem())) { currentInterObjScript.Unlock(); } currentInterObjScript.TriggerDialogue(); } } else if ((horizontal != 0 || vertical != 0) && IsMoveable()) //character control { if (IsMoving() && SameDirection(horizontal, vertical)) { UpdateDestination(horizontal, vertical); } else if (!IsMoving()) { SetDirection(horizontal, vertical); Move(horizontal, vertical); } currentInterObj = null; currentInterObjScript = null; } } }
private void Update() { if (Input.GetKeyDown(KeyCode.Tab) && !inDialogue && !Player.GetInstance().InBattle()) { ToggleMenu(); } else if (inMenu && !inDialogue) { Player.GetInstance().SetMoveable(false); if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.A)) { if (menuCursor != 0) { menuCursor--; FindObjectOfType <AudioManager>().Play("Click"); } UpdateMenu(); } else if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D)) { if (menuCursor != menuTextBoxes.Length - 1) { if (menuText[menuCursor + 1] != "") { menuCursor++; FindObjectOfType <AudioManager>().Play("Click"); } } UpdateMenu(); } } if (Input.GetKeyDown(KeyCode.Space)) { if (inDialogue) //Cycle Dialogue { bool endOfDialogue = DisplayNextSentence(); if (endOfDialogue && Player.GetInstance().HasInteractiveObject()) //End of Dialogue { InteractiveObject interObjScript = Player.GetInstance().GetInteractiveObjectScript(); inventory = Player.GetInstance().GetInventory(); if (Player.GetInstance().GetInteractiveObject().name == "Coffin" && interObjScript.Unlocked()) //Vampire Battle { Player.GetInstance().Battle(GameObject.Find("Vampire").GetComponent <Enemy>()); } else if (Player.GetInstance().GetInteractiveObject().name == "Cerberus" && interObjScript.Unlocked()) { Loader.Load(SceneName.Credits, new Vector3(-70.5f, -20.5f, 0)); } else { if (interObjScript.IsItem()) // Pickup Item { inventory.AddItem(interObjScript.GetItem()); Destroy(Player.GetInstance().GetInteractiveObject()); } else if (interObjScript.NeedsItem() && interObjScript.GivesItem() && inventory.HasItem(interObjScript.NeededItem())) //Perform Item Trade { inventory.RemoveItem(interObjScript.NeededItem()); inventory.AddItem(interObjScript.GetItem()); } } } } else if (inMenu) //Select Menu Option { if (menuText[menuCursor] == "Inventory") { inventory = Player.GetInstance().GetInventory(); if (inventory.NumItems() > 0) { ClearMenuText(); menuText = inventory.GetPage(0, menuTextBoxes.Length); UpdateMenu(); } else { string[] test = new string[] { "Doug's inventory is empty..." }; // create dialogue method, return dialougue as param for StartDialogue() Dialogue d = new Dialogue { sentences = test }; StartDialogue(d, DialogueType.Default); } } else if (menuText[menuCursor] == "Quit") { Loader.Load(SceneName.MainMenu, new Vector3(-7.5f, -2.5f, 0)); } } else if (Player.GetInstance().GetInteractiveObject() != null) //Interact With Game Object, starts Dialogue { InteractiveObject interObjScript = Player.GetInstance().GetInteractiveObjectScript(); inventory = Player.GetInstance().GetInventory(); if (interObjScript.NeedsItem() && inventory.HasItem(interObjScript.NeededItem())) { interObjScript.Unlock(); } interObjScript.TriggerDialogue(); } } }