예제 #1
0
        private void Update()
        {
            if (!Term.IsVisible())
            {
                // Don't do any "gameplay stuff" if the debug console is up

                // Handle inputs
                // Movement
                Vector3 Move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
                if (Move.sqrMagnitude != 0)
                {
                    Character.Move(Character.transform.TransformDirection(Move));
                }
                else if (Character.Moving())
                {
                    Character.Stop();
                }

                // Rotation (only when cursor is locked
                if (CursorHandler.Locked())
                {
                    Rotation.y += Input.GetAxis("Mouse X") * CursorHandler.GetMouseSensitivityX();
                    Rotation.x  = Mathf.Clamp(Rotation.x - Input.GetAxis("Mouse Y") * CursorHandler.GetMouseSensitivityY(), -89, 89);
                    Character.SetRotation(Rotation);
                }

                // Interactions
                bool       Interacted     = false;
                GameObject LookedAtObject = CameraUtil.GetLookedAtGameObject(Camera, Character.InteractionDistance);
                if (LookedAtObject != null)
                {
                    Interactable LookingAt = LookedAtObject.GetComponent <Interactable>();
                    if (LookingAt != null && (LookingAt.transform.position - Character.GetPosition()).magnitude < Character.InteractionDistance)
                    {
                        if (Input.GetButtonDown("Activate"))
                        {
                            InteractWith(LookingAt, InteractionType.Activate);
                            Interacted = true;
                        }
                        if (Input.GetButtonUp("Activate"))
                        {
                            InteractWith(LookingAt, InteractionType.Deactivate);
                            Interacted = true;
                        }
                        if (LookedAtObject != LastLookedAt)
                        {
                            InteractWith(LookingAt, InteractionType.Enter);
                            if (LastLookedAt != null)
                            {
                                InteractWith(LastLookedAt.GetComponent <Interactable>(), InteractionType.Exit);
                            }
                        }
                        LastLookedAt = LookedAtObject;
                    }
                }
                else if (LastLookedAt != null)
                {
                    InteractWith(LastLookedAt.GetComponent <Interactable>(), InteractionType.Exit);
                    LastLookedAt = null;
                }

                // Equipment actions
                if (!Interacted && !InventoryInterface.IsOpen())
                {
                    // Don't use equipment if you're interacting with something
                    // (ie. don't shoot at the buttons)
                    if (Input.GetButtonDown("Use Item (R)"))
                    {
                        Character.Inventory.UseItemInSlot(EquipSlot.RightHand);
                        Client.Send(PktType.InventoryAction, Character.Inventory.ActionHandler.BuildUseItem(EquipSlot.RightHand));
                    }
                    if (Input.GetButtonDown("Use Item (L)"))
                    {
                        Character.Inventory.UseItemInSlot(EquipSlot.LeftHand);
                        Client.Send(PktType.InventoryAction, Character.Inventory.ActionHandler.BuildUseItem(EquipSlot.LeftHand));
                    }
                }
            }
            else if (Character.Moving())
            {
                // The debug console is open, stop the player.
                Character.Stop();
            }
        }