Exemplo n.º 1
0
    void Update()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        // TODO extract those to a function
        if (Input.GetMouseButtonDown(0)) // LMB
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, raycastMaxDistance, movementMask))
            {
                playerMotor.MoveToPoint(hit.point);
                RemoveFocus();
            }
        }
        else if (Input.GetMouseButtonDown(1)) // RMB
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, raycastMaxDistance, movementMask))
            {
                Interactable interactable = hit.collider.GetComponent <Interactable>();
                interactable?.Also(it =>
                {
                    SetFocus(it);
                });
            }
        }
    }