Unity3D 范围检测 扇形 圆形 矩形 等腰三角形

代码如下:

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 

你可能感兴趣的:(Unity3D,开发日常随笔,Unity3D开发日常随笔)