//发射一条射线,去检测玩家是否在自己面前,用来随后的发射炮弹 bool isForward = false; var TranformShootPoint = ai.WorkingMemory.GetItem("enemyShootPoint"); Ray ray = new Ray(TranformShootPoint.transform.position, TranformShootPoint.transform.forward); RaycastHit hit;//这个是碰撞检测的目标 if (Physics.Raycast(ray, out hit, 5))//传入的参数依次是:射线、射线碰撞物、射线检测距离 { GameObject obj = hit.transform.gameObject;//得到碰撞的游戏对象 if (obj.tag == "Player") { isForward = true; } }