AI案列 三條路
阿新 • • 發佈:2018-09-08
+= each ram per 自身 eric .get destroy for
在生成點生成帶有顏色的小球,小球走對應顏色的路
先做好三個小球,做成預制體
對應顏色的小球,除了自身顏色,其他顏色不要選
新建腳本:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class xunlu002 : MonoBehaviour { public float time = 0; public Transform target; public Transform tr;//生成點 public GameObject[] obj = new GameObject[3]; private NavMeshAgent agent; GameObject go; List<GameObject> c = new List<GameObject>(); // Use this for initialization void Start () { } // Update is called once per frame void Update () { time+= Time.deltaTime; if (time > 2) { go = Instantiate(obj[Random.Range(0, obj.Length)], tr.position, Quaternion.identity); go.GetComponent<NavMeshAgent>().destination = GameObject.Find("target").transform.position; c.Add(go); time= 0; } foreach (GameObject item in c) { if (Vector3.Distance( item.transform.position, target.position) <= 1.1f) { Destroy(item,1); c.Remove(item); } } } }
AI案列 三條路