ドキュメント

Unity Engine

Unity Engine

IntersectRay

Does ray intersect this bounding box?
読み終わるまでの所要時間 1 分最終更新 1ヶ月前

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

IntersectRay(Ray)

Does ray intersect this bounding box?
public bool IntersectRay(Ray ray)

Parameters

ray

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 ray intersect this bounding box?
public bool IntersectRay(Ray ray, out float distance)

Parameters

ray


distance

Returns

Type

Description

bool

Remarks

When the function returns true, the distance to the ray's origin will be returned in the distance parameter.