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); }
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); }
// Start is called before the first frame update void Start() { Launcher = LaunchersObject.GetComponent <BallLauncherController>(); Ray = RayCast.GetComponent <RaycastMaster>(); text = TextObj.GetComponent <Text>(); TotText = TotTextObj.GetComponent <Text>(); }
protected override void OnMouseDrag() { if (disabled) { return; } transform.position = cursorOnTransform + dragRelative; DropBox nextBox = RaycastMaster.ComponentUnderCursor <DropBox>(collidr); if (nextBox) { dropBox = nextBox; dropBox.canAccept(transform); } else { if (dropBox) { dropBox.cancel(); dropBox = null; } } }