Version: 2023.1

Bounds.IntersectRay

切换到手册
public bool IntersectRay (Ray ray);

描述

ray 是否与该包围盒交叠?

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); } }

public bool IntersectRay (Ray ray, out float distance);

描述

ray 是否与该包围盒交叠?

当此函数返回 true 时,将在 distance 参数中返回到该光线原点的距离。