Esempio n. 1
0
        /// <summary>
        /// Handle player's input
        /// </summary>
        public void HandleInput()
        {
            if (CameraController.isLooking)
            {
                return;
            }

            if (!CursorController.IsCursorOverUI())
            {
                if (Input.GetButtonDown("Move"))
                {
                    movementClickCooldown = 0;
                }

                if (Input.GetButton("Move") && movementClickCooldown <= 0)
                {
                    RaycastHit hit;
                    Ray        ray = m_Camera.ScreenPointToRay(Input.mousePosition);

                    if (Physics.Raycast(ray, out hit, Mathf.Infinity, moveLayerMask))
                    {
                        positionSynchronization.CmdSetDestination(hit.point);
                    }
                    target = null;

                    movementClickCooldown = 0.25f;
                }
                if (Input.GetButtonDown("Attack") && usedWeapon)
                {
                    RaycastHit hit;
                    Ray        ray = m_Camera.ScreenPointToRay(Input.mousePosition);

                    if (Physics.Raycast(ray, out hit) && (hit.transform.tag == "Player" || hit.transform.tag == "Entity"))
                    {
                        float  distance = Vector3.Distance(transform.position, hit.transform.position);
                        Entity entity   = hit.transform.GetComponent <Entity>();

                        if (distance < usedWeapon.attackRange)
                        {
                            SetTarget(entity);
                        }
                        else
                        {
                            SetTarget(entity);
                            SetDestinationToEntity(entity);
                        }
                    }
                }
            }

            if (Input.GetButtonDown("ClosestEnemy"))
            {
                target = GetClosestEntity();
            }

            #region //======    TOOLBAR    ======\\

            for (int i = 1; i <= 9; i++)
            {
                if (Input.GetButtonDown("Toolbar" + i))
                {
                    ToolbarCellUI toolbarCell = InventorySystem.GetToolbarCell(i - 1);
                    if (toolbarCell & toolbarCell.Cell)
                    {
                        toolbarCell.Cell.item.UseItem(new Vector2Byte(toolbarCell.Cell.indexPosition));
                    }
                }
            }

            #endregion

            if (Input.GetKeyDown(KeyCode.E))
            {
                ItemData data = new ItemData(0, 15);
                CmdAddItem(data);
            }
        }