MGames

بازی سازی یونیتی توسط MGames

MGames

بازی سازی یونیتی توسط MGames

MGames

ساخت بازی با یونیتی توسط گروه MGames و همچنین اراعه ی بازی های این گروه در این وبلاگ

دنبال کنندگان ۳ نفر
این وبلاگ را دنبال کنید
طبقه بندی موضوعی
آخرین نظرات
  • ۲ تیر ۹۵، ۲۳:۱۲ - amr
    عالی
نویسندگان

آموزش مسیریابی نقطه ای در یونیتی (Waypoint)

خب اینم از کد :

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

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();
        }
    }

نظرات  (۰)

هیچ نظری هنوز ثبت نشده است
ارسال نظر آزاد است، اما اگر قبلا در بیان ثبت نام کرده اید می توانید ابتدا وارد شوید.
شما میتوانید از این تگهای html استفاده کنید:
<b> یا <strong>، <em> یا <i>، <u>، <strike> یا <s>، <sup>، <sub>، <blockquote>، <code>، <pre>، <hr>، <br>، <p>، <a href="" title="">، <span style="">، <div align="">
تجدید کد امنیتی