如何修复我的敌人在游戏模式 UNITY 中隐形的问题
所以,这是我的错误!我统一设计了一个 FPS 游戏,并编写了一个 AI 敌人的脚本(现在它只是随机移动),我还使用 NeoFPS,这应该是所有发生的事情的背景信息: 我可以在场景视图中看到敌人,并且在按下“播放”之前,我可以在游戏视图中看到它,当我按下“播放”时,敌人会在游戏视图中消失,但我仍然可以看到它试图在我放入的小盒子周围移动以及通过导航网格等进行的各种东西。当我进入盒子时,敌人的碰撞器仍然在那里,但是我看不到它,我射击它并且不会对其造成任何损坏,我将在下面包含屏幕截图和我的AI代码(白色胶囊是敌人 w AI脚本在一个小盒子里,相机是FPS播放器
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class AICharacterController : MonoBehaviour
{
private NavMeshAgent m_Agent;
private void Awake()
{
m_Agent = GetComponent<NavMeshAgent>();
}
Vector3 movePosition;
void Update()
{
if (movePosition == Vector3.zero
|| Vector3.Distance(transform.position, m_Agent.destination) < 1)
{
SelectNewDestination();
}
}
void SelectNewDestination()
{
Vector2 pos = Random.insideUnitCircle * 50;
movePosition.x = pos.x;
movePosition.y = pos.y;
NavMeshHit hit = default;
if (NavMesh.SamplePosition(movePosition, out hit, 4, NavMesh.AllAreas))
{
m_Agent.SetDestination(hit.position);
}
}
public void Die()
{
Destroy(gameObject, 0.25f);
}
}
(如果你没有看到下面的图像,那么stackoverflow将其替换为链接并且它不起作用)
So, here's my error! im designing a FPS game in unity and im scripting an AI enemy (for now it just moves around randomly) im also using NeoFPS that should be all the background info out of the way as for whats happening:
i can see the enemy in scene view and i can see it in the game view before i press play, when i do press play the enemy disappears in game view but i can still see it trying to move around the little box i put it in and stuff of the sorts via navmesh etc. the collider for the enemy is still there when i go into the box however i cant see it and i shoot through it and do no damage to it whatsoever i will include screenshots and my AI code below (the white capsule is the enemy w AI script inside a little box, the camera is the FPS player
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class AICharacterController : MonoBehaviour
{
private NavMeshAgent m_Agent;
private void Awake()
{
m_Agent = GetComponent<NavMeshAgent>();
}
Vector3 movePosition;
void Update()
{
if (movePosition == Vector3.zero
|| Vector3.Distance(transform.position, m_Agent.destination) < 1)
{
SelectNewDestination();
}
}
void SelectNewDestination()
{
Vector2 pos = Random.insideUnitCircle * 50;
movePosition.x = pos.x;
movePosition.y = pos.y;
NavMeshHit hit = default;
if (NavMesh.SamplePosition(movePosition, out hit, 4, NavMesh.AllAreas))
{
m_Agent.SetDestination(hit.position);
}
}
public void Die()
{
Destroy(gameObject, 0.25f);
}
}
(if you dont see an image below then stackoverflow replaced it with a link and its not working)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果物体在相机中不可见,但在场景视图中不可见,则意味着相机上的“剔除蒙版”属性设置为忽略对象所在的图层。 NeoFPS 使用生成系统,因此生成的角色中的摄像机很可能与您在游戏模式之外查看的场景中的摄像机具有不同的剔除蒙版设置。要解决这个问题,您必须在角色预制件的层次结构(通常称为 PlayerCameraSpring)中找到相机,并将 AI 图层添加到其剔除蒙版中。
If things are invisible in a camera, but not in the scene view then that means that the "Culling Mask" property on the camera is set to ignore the layers the object is on. NeoFPS uses a spawning system, so its quite possible that the camera in the character that's spawned has a different culling mask setup to the camera in the scene that you're looking through outside of play mode. To fix that you would have to find the camera in the character prefab's hierarchy (usually called PlayerCameraSpring) and add your AI's layer to its culling mask.