public float fraction ;

描述

射线上发生命中的距离的分数。

如果射线的方向矢量是标准化的,则此值只是原点与命中点之间的距离。如果方向不是标准化的,则此距离表示为矢量大小的“分数”(可以大于 1)。

另请参阅:point

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Vector2 direction;

void Update() { //Cast a ray in the direction specified in the inspector. RaycastHit2D hit = Physics2D.Raycast(this.gameObject.transform.position, direction, 10.0f);

//If something was hit. if (hit.collider != null) { Debug.Log(hit.fraction); } } }