言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Bounds.IntersectRay

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public function IntersectRay(ray: Ray): bool;
public bool IntersectRay(Ray ray);
public def IntersectRay(ray as Ray) as bool

Description

/ray/ が交差しているか確認します

	// Creates a ray that points from the origin to the infinity among the z Axis.
	// And prints if the transform touched the ray.

	var ra : Ray  = new Ray (Vector3.zero, Vector3.forward);;

	function Update () {
	    // Color ra in the scene editor.
	    Debug.DrawRay (Vector3.zero, Vector3.forward * 999, Color.green);
	    var bounds : Bounds = transform.collider.bounds;
	    if (bounds.IntersectRay (ra))
	        Debug.Log("Touched the ray");
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Ray ra = new Ray(Vector3.zero, Vector3.forward);
    void Update() {
        Debug.DrawRay(Vector3.zero, Vector3.forward * 999, Color.green);
        Bounds bounds = transform.collider.bounds;
        if (bounds.IntersectRay(ra))
            Debug.Log("Touched the ray");
        
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public ra as Ray = Ray(Vector3.zero, Vector3.forward)

	def Update() as void:
		Debug.DrawRay(Vector3.zero, (Vector3.forward * 999), Color.green)
		bounds as Bounds = transform.collider.bounds
		if bounds.IntersectRay(ra):
			Debug.Log('Touched the ray')

public function IntersectRay(ray: Ray, distance: float): bool;
public bool IntersectRay(Ray ray, float distance);
public def IntersectRay(ray as Ray, distance as float) as bool

Description

/ray/ が交差しているか確認します

IntersectRayがtrueを返すとき、距離はレイの原点からの距離になります。

	// Creates a ray that points from the origin to 10 units among the z Axis.
	// And prints if the transform touched the ray.

	var ra : Ray = new Ray (Vector3.zero, Vector3.forward);;
	var t : float = 10.0;

	function Update () {
	    // Color ra in the scene editor.
	    Debug.DrawRay (Vector3.zero, Vector3.forward * 10, Color.green);
	    var bounds : Bounds = transform.collider.bounds;
	    if (bounds.IntersectRay (ra, t))
	        Debug.Log("Touched the ray");
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Ray ra = new Ray(Vector3.zero, Vector3.forward);
    public float t = 10.0F;
    void Update() {
        Debug.DrawRay(Vector3.zero, Vector3.forward * 10, Color.green);
        Bounds bounds = transform.collider.bounds;
        if (bounds.IntersectRay(ra, out t))
            Debug.Log("Touched the ray");
        
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public ra as Ray = Ray(Vector3.zero, Vector3.forward)

	public t as float = 10.0F

	def Update() as void:
		Debug.DrawRay(Vector3.zero, (Vector3.forward * 10), Color.green)
		bounds as Bounds = transform.collider.bounds
		if bounds.IntersectRay(ra, ):
			Debug.Log('Touched the ray')