Beispiel #1
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);
            }
        }
    }