IntersectRay
Does ray intersect this bounding box?
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
IntersectRay(Ray)
Does intersect this bounding box?
raypublic readonly bool IntersectRay(Ray ray)
Parameters
Returns
Type | Description |
|---|---|
| bool |
Examples
using UnityEngine;public class Example : MonoBehaviour{ // Function to detect if a ray (representing a beam weapon, say) // makes contact with the collider's bounds. Collider myCollider; void Start() { // Store a reference to the collider once at startup. myCollider = GetComponent<Collider>(); } bool DetectHit(Ray ray) { return myCollider.bounds.IntersectRay(ray); }}
IntersectRay(Ray)
Does intersect this bounding box?
raypublic readonly bool IntersectRay(in Ray ray)
Parameters
Returns
Type | Description |
|---|---|
| bool |
Examples
using UnityEngine;public class Example : MonoBehaviour{ // Function to detect if a ray (representing a beam weapon, say) // makes contact with the collider's bounds. Collider myCollider; void Start() { // Store a reference to the collider once at startup. myCollider = GetComponent<Collider>(); } bool DetectHit(Ray ray) { return myCollider.bounds.IntersectRay(ray); }}
IntersectRay(Ray, float)
Does intersect this bounding box?
raypublic readonly bool IntersectRay(Ray ray, out float distance)
Parameters
Returns
Type | Description |
|---|---|
| bool |
Remarks
When the function returns true, the distance to the ray's origin will be returned in the parameter.
distanceIntersectRay(Ray, float)
Does intersect this bounding box?
raypublic readonly bool IntersectRay(in Ray ray, out float distance)
Parameters
Returns
Type | Description |
|---|---|
| bool |
Remarks
When the function returns true, the distance to the ray's origin will be returned in the parameter.
distance