在Unity3D中,我用一个简单的敌人ai脚本创建了一个僵尸字符,这样僵尸就会追上播放器,但是当我添加NavMeshAgent组件时,它声明了以下错误消息:
只能对放置在NavMesh.UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)上的活动代理调用
"SetDestination“。
我已经试过烘焙NavMesh,但它没有工作,请帮助我卡住了。这是我的密码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UIElements;
public class EnemyAI : MonoBehaviour
{
public float lookRadius = 20f;
Transform target;
NavMeshAgent agent;
// Start is called before the first frame update
void Start()
{
agent = GetComponent<NavMeshAgent>();
target = PlayerManager.instance.player.transform;
}
// Update is called once per frame
void Update()
{
float distance = Vector3.Distance(target.position, transform.position);
if (distance <= lookRadius)
{
agent.SetDestination(target.position);
}
if (distance <= agent.stoppingDistance)
{
FaceTarget();
}
void FaceTarget()
{
Vector3 direction = (target.position - transform.position).normalized;
Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * 5f);
}
}
public void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, lookRadius);
}
}发布于 2020-04-26 11:18:14
问题解决了,我只需检查地面的静态和烘烤NavMeshAgent。希望它能帮上忙
https://stackoverflow.com/questions/61386001
复制相似问题