简体   繁体   中英

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. 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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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