Esempio n. 1
0
    void OnMouseDrag()
    {
        anchorHj2d.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        Vector3 mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);

        RaycastHit2D[] hits = Physics2D.RaycastAll(mousePos2D, Vector2.zero);
        bool           hoveredTargetFound = false;

        foreach (RaycastHit2D hit in hits)
        {
            if (hit.collider != null && hit.collider.gameObject.GetComponent <InteractionTarget>() != null)
            {
                if (hoveredTarget != null && hoveredTarget != hit.collider.gameObject.GetComponent <InteractionTarget>())
                {
                    hoveredTarget.itemHoverExit(itemType);
                }
                hoveredTarget = hit.collider.gameObject.GetComponent <InteractionTarget>();
                hoveredTarget.itemHoverEntered(itemType);
                hoveredTargetFound = true;
                break;
            }
        }
        if (!hoveredTargetFound && hoveredTarget != null)
        {
            hoveredTarget.itemHoverExit(itemType);
            hoveredTarget = null;
        }
    }