我创建了一个类来移动游戏对象,如下所示:
public class Navmesh_move : MonoBehaviour {
private NavMeshAgent _thismove;
Transform test;
//Vector3 destenation_Pos;
Vector3 destenation_Position,vector3test;
// Use this for initialization
public void move(float x,float y,float z)
{
//this.transform.Rotate (0, 0, 180);
_thismove =this.gameObject.GetComponent<NavMeshAgent>();
destenation_Position = new Vector3(x,y,z);
_thismove.SetDestination(destenation_Position);
NavMeshAgent tempnavmesh = new NavMeshAgent ();
tempnavmesh =this.gameObject.GetComponent<NavMeshAgent> ();
tempnavmesh.enabled = false;
//this.transform.position=destenation_Position;
}}
然后,我将其归因于一个对象游戏。
但是在添加tempnavmesh.enabled = false;之前,我的游戏对象移动了correct.but,在添加那一行之后,我得到了"SetDestination" can only be called on an active agent that has been placed on a NavMesh.错误,并且我的游戏对象不能移动。
如何在移动游戏对象后删除navmeshAgent组件?
发布于 2017-12-23 01:12:42
我已经找到了解决我的问题的办法。看起来像这样:
public void move(float x,float y,float z)
{
//this.transform.Rotate (0, 0, 180);
_thismove =this.gameObject.GetComponent<NavMeshAgent>();
destenation_Position = new Vector3(x,y,z);
_thismove.SetDestination(destenation_Position);
Invoke ("disablenavmeshagent", 2);
}
//-------------------------------------
void disablenavmeshagent()
{
NavMeshAgent tempnavmesh = new NavMeshAgent ();
tempnavmesh =this.gameObject.GetComponent<NavMeshAgent> ();
tempnavmesh.enabled = false;
}https://stackoverflow.com/questions/47939026
复制相似问题