Legacy Documentation: Version 2017.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Bounds.IntersectRay

public bool IntersectRay(Ray ray);

Description

Does ray intersect this bounding box?

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Collider coll; void Start() { coll = GetComponent<Collider>(); } bool DetectHit(Ray ray) { return coll.bounds.IntersectRay(ray); } }

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

Description

Does ray intersect this bounding box?

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

Did you find this page useful? Please give it a rating: