简单判断玩家是否在怪物视野内的代码

 float dotResult = Vector3.Dot(this.transform.forward, PlayerObject.transform.position - this.transform.position);

        float angle = 1000f;
        if (dotResult > 0)
        {
            angle = Vector3.Angle(this.transform.forward, PlayerObject.transform.position - this.transform.position);
        }
        float distance = Vector3.Distance(PlayerObject.transform.position, transform.position);

        if (angle < 60f && distance < 4f)
        {
            Debug.Log("玩家在怪物视野内");
        }else
        {
            Debug.Log("玩家不在怪物视野内");
        }

你可能感兴趣的:(简单判断玩家是否在怪物视野内的代码)