<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                本文章由cartzhang編寫,轉載請注明出處。 所有權利保留。 文章鏈接:?http://blog.csdn.net/cartzhang/article/details/47337029 作者:cartzhang 對與U3D ?AI,看了下,自己做了小功能,以備后用啊! ### 一,在某區域隨機產生某個對象 C# 文件名稱為RadomAPoint.cs ~~~ using UnityEngine; using System.Collections; public class RadomAPoint : MonoBehaviour { public GameObject mObjArea; // 隨機區域 public GameObject prefabObj; // 對象prefab public string mytag; // 對象標簽 public string targetTag; // 目標對象標簽 public int ObjectNumber; // 場景中整體prefab 個數。 private Bounds mbouds; private Vector3 tmp; // Use this for initialization void Start () { mbouds = mObjArea.GetComponent<Collider>().bounds; InvokeRepeating("NewPrefabInstance", 1, 5);//1秒后調用LaunchProjectile () 函數,之后每5秒調用一次 } // Update is called once per frame void Update () { } void NewPrefabInstance() { GameObject[] root = GameObject.FindGameObjectsWithTag(mytag); if (root.Length <= ObjectNumber) { Vector3 randomPos = RadomVector3(mbouds.min, mbouds.max); //GameObject tmpGameObj = Resources.Load(prefabName) as GameObject; //tmpGameObj.transform.position = randomPos; Quaternion q = Quaternion.identity; GameObject tmpGameObj = GameObject.Instantiate(prefabObj, randomPos, q) as GameObject; tmpGameObj.GetComponent<AIBehaviourScript>().TargetObject = GameObject.FindWithTag(targetTag).transform; } } Vector3 RadomVector3(Vector3 min, Vector3 max) { tmp.x = Random.Range(min.x, max.x); tmp.y= Random.Range(min.y, max.y); return tmp; } } ~~~ ### 二、自己做了個prefab,添加了自動找到目標的功能。 特別簡單的代碼: ~~~ using UnityEngine; using System.Collections; public class AIBehaviourScript : MonoBehaviour { public Transform TargetObject = null; void Start() { if (TargetObject != null) { GetComponent<NavMeshAgent>().destination = TargetObject.position; } } void Update() { } } ~~~ ### 三,遇到目標后,自動銷毀 代碼: ~~~ using UnityEngine; using System.Collections; public class BoxCollisionDestory : MonoBehaviour { public string tagName; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnTriggerEnter(Collider other) { if (other.gameObject.tag == tagName) { GameObject.Destroy(other.gameObject); } } } ~~~ ### 四,說明 這個過程中,要設置目標點為的屬性如下: ![](https://box.kancloud.cn/2016-03-09_56dfda817c4f3.jpg) 而prefab對象也需要給它一個rigidbody,否則他們的碰撞不起作用。 ![](https://box.kancloud.cn/2016-03-09_56dfda8522543.jpg) 基本上做了一個能隨機位置產生一個對象,然后對象自動尋找目的,到達目的地的小功能! --------- 若有問題,請隨時聯系! 非常感謝!!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看