首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >移动后删除navmesh组件

移动后删除navmesh组件
EN

Stack Overflow用户
提问于 2017-12-22 17:30:15
回答 1查看 699关注 0票数 0

我创建了一个类来移动游戏对象,如下所示:

代码语言:javascript
复制
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组件?

EN

回答 1

Stack Overflow用户

发布于 2017-12-23 01:12:42

我已经找到了解决我的问题的办法。看起来像这样:

代码语言:javascript
复制
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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47939026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档