简体   繁体   English

如何修复我的敌人在游戏模式 UNITY 中变得隐形

[英]how to fix my enemy turning invisible in play mode UNITY

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.所以,这是我的错误:我正在统一设计一个 FPS 游戏,我正在编写一个 AI 敌人的脚本(现在它只是随机移动)我还在使用 NeoFPS,它应该是关于发生的事情的所有背景信息,我可以在场景视图中看到敌人,在我按下播放之前我可以在游戏视图中看到它。 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当我按下播放键时,敌人会在游戏视图中消失,但我仍然可以看到它试图在我放入的小盒子周围移动以及通过导航网格等进行的各种操作,当我进入 go 时,敌人的对撞机仍然存在盒子,但是我看不到它,我通过它射击并且没有损坏它我将在下面包含屏幕截图和我的 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);
        }

}

(if you dont see an image below then stackoverflow replaced it with a link and its not working) (如果您没有看到下面的图片,则 stackoverflow 将其替换为链接并且它不起作用)

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.如果事物在相机中不可见,但在场景视图中不可见,则意味着相机上的“Culling Mask”属性设置为忽略 object 所在的图层。 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. NeoFPS 使用生成系统,因此很可能生成的角色中的摄像机与您在游戏模式外查看的场景中的摄像机具有不同的剔除遮罩设置。 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.要解决这个问题,您必须在角色预制件的层次结构(通常称为 PlayerCameraSpring)中找到相机,并将您的 AI 层添加到它的剔除遮罩中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM