用点乘和叉乘再加if嵌套即可完成
Vector3 a = Vector3.Cross(transform.forward, dog.transform.position - transform.position);
float pos = Vector3.Dot(transform.forward, dog.transform.position - transform.position);
if (a.y > 0)
{
if (pos >= 0)
{
print("在玩家右前方" + pos + "度数" + a.y);
if (a.y < 30 && a.y > 0 && (int)pos <= 5f)
{
print("发现入侵者");
}
}
else
{
print("在玩家右后方" + pos + "度数" + a.y);
}
}
else
{
if (pos >= 0)
{
print("在玩家左前方" + pos + "度数" + a.y);
if (a.y < 20 && a.y > 0 && pos >= (-5f))
{
print("发现入侵者");
}
}
else
{
print("在玩家左后方" + pos + "度数" + a.y);
}
}