خرید بک لینک

gameover.blog.ir


خب اینم از کد :


توضیحات کد زیر :


agent.autoBraking به وسیله این کد میشه برای آبجکتمون تعریف کرد که به حرکت خودش ادامه بده (در صورت false بودن)

agent.destination این کد هم مسیر رو تنظیم می کنه

% در زیان C# عملگر باقی مانده هست

points.Length اندازه متغییر های درون آرایه points رو بهمون میده مثلا شما توی points چهار متغییر برای نقاط روی نقشه گزاشتید این کد هم 4 رو بر میگردونه

agent.remainingDistnace این کد مقدار فاصله مونده تا مقصد رو بر میگردونه

خب بقیه رو خودتون باید درک کنید من توضیح خاصی توی کد نمی بینم


اگر کد کار نکرد :

-چک کنید Navigation رو درست انجام دادید

-چک کنید که points ها رو هم به اسکریپت نسبت داده باشید

-آبجکتی که اسکریپت رو بهش دادید باید NavMeshAgent داشته باشه

    // Patrol.cs
    using UnityEngine;
    using System.Collections;


    public class Patrol : MonoBehaviour {

        public Transform[] points;
        private int destPoint = 0;
        private NavMeshAgent agent;


        void Start () {
            agent = GetComponent<NavMeshAgent>();

            // Disabling auto-braking allows for continuous movement
            // between points (ie, the agent doesn't slow down as it
            // approaches a destination point).
            agent.autoBraking = false;

            GotoNextPoint();
        }


        void GotoNextPoint() {
            // Set the agent to go to the currently selected destination.
            agent.destination = points[destPoint].position;

            // Choose the next point in the array as the destination,
            // cycling to the start if necessary.
            destPoint = (destPoint + 1) % points.Length;
        }


        void Update () {
            // Choose the next destination point when the agent gets
            // close to the current one.
            if (agent.remainingDistance < 0.5f)
                GotoNextPoint();
        }
    }

برچسب: نویسنده: ایلیا حیدری تاريخ: چهارشنبه 14 مهر 1395 ساعت: 11:50

صفحه بندی