Ejemplo n.º 1
0
    public static bool CursorRayhit(Collider coll, out RaycastHit rh)
    {
        Ray       ray      = Camera.main.ScreenPointToRay(Input.mousePosition);
        LayerMask collMask = LayerMask.GetMask(LayerMask.LayerToName(coll.gameObject.layer));
        int       i        = 0;

        do
        {
            if (Physics.Raycast(ray, out rh, 100f, collMask))
            {
                if (rh.collider == coll)
                {
                    return(true);
                }
                else
                {
                    ray = RaycastMaster.RaySlightlyBelowHit(ray, rh);
                }
            }
            else
            {
                break;
            }
        } while (++i < 5);
        return(false);
    }
Ejemplo n.º 2
0
    public static HashSet <Collider> CollidersPiercedBy <T>(Ray ray, int depth, LayerMask layerMask, bool wantCursorInteraction) where T : MonoBehaviour
    {
        RaycastHit         rayHit;
        HashSet <Collider> ciColliders = new HashSet <Collider>();

        for (int i = 0; i < 5; ++i)
        {
            if (Physics.Raycast(ray, out rayHit, 100f, layerMask))
            {
                //TODO: iron-out awkward logic here. Could use a dynamic type? instead of the 'want' bool?
                if (wantCursorInteraction && rayHit.collider.GetComponentInParent <T>() == null)
                {
                    break;
                }
                else
                {
                    ray = RaycastMaster.RaySlightlyBelowHit(ray, rayHit);
                    ciColliders.Add(rayHit.collider);
                }
            }
            else
            {
                break;
            }
        }
        return(ciColliders);
    }