using UnityEngine;
using System.Collections;
public class NewBehaviourScript :MonoBehaviour
{
public Transform planeTarget;
public Transform target;
void Update ()
{
if (!planeTarget) {
Debug.LogWarning ("planeTarget is null");
return;
}
if (!target) {
Debug.LogWarning ("target is null");
return;
}
//Plane 类提供了处理平面所用到的基本算法
//3的点构成一个面,或者坐标和法线构成一个面
//这里使用planeTarget 坐标和法线,平面的法线也就是正面方向(up方向)
Plane plane = new Plane (planeTarget.up,planeTarget.position);
float distance = plane.GetDistanceToPoint (target.position);
Debug.Log ("distance:" + distance);
}
}
using System.Collections;
public class NewBehaviourScript :MonoBehaviour
{
public Transform planeTarget;
public Transform target;
void Update ()
{
if (!planeTarget) {
Debug.LogWarning ("planeTarget is null");
return;
}
if (!target) {
Debug.LogWarning ("target is null");
return;
}
//Plane 类提供了处理平面所用到的基本算法
//3的点构成一个面,或者坐标和法线构成一个面
//这里使用planeTarget 坐标和法线,平面的法线也就是正面方向(up方向)
Plane plane = new Plane (planeTarget.up,planeTarget.position);
float distance = plane.GetDistanceToPoint (target.position);
Debug.Log ("distance:" + distance);
}
}