Ejemplo n.º 1
0
    void Update()
    {
        if (camera == null)
        {
            return;
        }

        Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out RaycastHit hitInfo, maxDist);

        IClickable t = hitInfo.transform?.GetComponent <IClickable>();

        //MouseOver
        if (t != current)
        {
            current?.OnMouseOverEnd();

            t?.OnMouseOverBegin();
        }

        current = t;

        //Clicks
        if (t != null && Input.GetMouseButtonDown(0))
        {
            if (clickCo == null)
            {
                clickCo = StartCoroutine(Click(0, current));
            }
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (camera == null)
        {
            return;
        }

        Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out RaycastHit hitInfo, maxDist);

        IClickable hitThisFrame = hitInfo.transform?.GetComponent <IClickable>();

        //MouseOver
        if (hitThisFrame != current)
        {
            current?.OnMouseOverEnd();

            hitThisFrame?.OnMouseOverBegin();
        }

        current = hitThisFrame;

        //Clicks
        if (hitThisFrame != null)
        {
            if (Input.GetMouseButtonDown(0))
            {
                hitThisFrame.OnLeftClickStart();
            }
            else if (Input.GetMouseButtonUp(0))
            {
                hitThisFrame.OnLeftClickEnd();
            }
            else
            {
                hitThisFrame.OnLeftClickMoved(Input.mousePosition);
            }
        }
    }