Example #1
0
    // Update is called once per frame
    void Update()
    {
        switch (cursorState)
        {
        case CursorState.NORMAL:
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100f))
                {
                    TryPickUp(hit);
                }
            }
            break;

        case CursorState.HOLDING:
            if (pickedObject != null)
            {
                RaycastHit hit;
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100f, groundLayerMask))
                {
                    if (hit.collider != null)     //Could it be null ?
                    {
                        Vector3 newPosition = hit.point + Vector3.up;
                        pickedObject.SetPosition(newPosition);
                    }
                }
            }
            break;
        }
    }