Transform的扩展
如果想扩展系统类的话,就写一个静态函数,第一个参数类型就是想扩展的类名,用this标记
判断目标是否面朝你
public static bool IsFacingTarget(this Transform transform,Transform target)
{
Vector3 vectorToTarget = target.position - transform.position;
vectorToTarget.Normalize();
float dot = Vector3.Dot(transform.forward,vectorToTarget);
return dot >= 0.5f;
}