代码如下:
using UnityEngine;
public class RangeCheck
{
//--扇形
public static bool CurveRange(Transform self, Transform target, float maxDistance, float maxAngle)
{
return CurveRange(self, target, 0, maxDistance, maxAngle);
}
public static bool CurveRange(Transform self, Transform target, float minDistance, float maxDistance, float maxAngle)
{
Vector3 playerDir = self.forward;
Vector3 enemydir = (target.position - self.position).normalized;
float angle = Vector3.Angle(playerDir, enemydir);
if (angle > maxAngle * 0.5f)
{
return false;
}
float distance = Vector3.Distance(target.position, self.position);
if (distance <= maxDistance && distance >= minDistance)
{
return true;
}
return false;
}
//--圆形
public static bool CircleRange(Transform self, Tra