Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(197评价)
价格: 4431.00元
【秘密行动】机器人的NavMesh与模型走着走着就分离了,没达到预期巡逻效果
聖御丶发起了问答2019-03-06
2
回复
416
浏览
    

    public Transform[] wayPoints;
    private int index = 0;
    private NavMeshAgent navAgent;

    private float patrolWaitTime=3f;
    private float patrolWaitTimer=0;
    // Use this for initialization
    void Awake () {
        navAgent = GetComponent<NavMeshAgent>();
        navAgent.destination = wayPoints[index].position;
        navAgent.updatePosition = false;
        navAgent.updateRotation = false;

    }
    private void Patrolling()
    {
        navAgent.speed = 2.5f;
        navAgent.destination = wayPoints[index].position;
        navAgent.updatePosition = false;
        navAgent.updateRotation = false;
        if (navAgent.remainingDistance<0.5f)
        {
            patrolWaitTimer += Time.deltaTime;
            if (patrolWaitTimer>patrolWaitTime)
            {
                index++;
                index %=wayPoints.Length;
                navAgent.destination = wayPoints[index].position;
                navAgent.updatePosition = false;
                navAgent.updateRotation = false;
                patrolWaitTimer = 0;
            }

        }
    }

秘密行动第33课,控制机器人行走动画,代码是跟老师一样的,但是我运行的时候机器人总是模型与NavMesh分离了,请教是哪里出了问题?

 

 

所有回复
发表回复
你还没有登录,请先 登录或 注册!