using System.Collections; using System.Collections.Generic; using UnityEngine; public class WRJController : MonoBehaviour { public List wayPoints = new List(); public int index1 = 0; public float speed; public HuoPaoController[] huoPaoControllerList; public bool isMove = false; public float dis; public float limitDis; public Transform firePos; public GameObject firePrefab; public bool isGoToPlace = false; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (wayPoints.Count == 0) return; if (isMove) { MoveToway1(); } if (isGoToPlace) { InvokeRepeating("OnFire", 1, 1); isGoToPlace = false; } } public void MoveToway1() { if (index1 > wayPoints.Count - 1) { return; } transform.localPosition = Vector3.MoveTowards(transform.localPosition, wayPoints[index1], speed * Time.deltaTime); if (Vector3.Distance(wayPoints[index1], transform.localPosition) < 0.01f) { index1++; if (index1 == wayPoints.Count) { transform.localPosition = wayPoints[index1 - 1]; isGoToPlace = true; isMove = false; } } } public int currentHuoPaoIndex = 0; private void OnFire() { //for (int i = 0; i < huoPaoControllerList.Length; i++) //{ if (currentHuoPaoIndex > huoPaoControllerList.Length - 1) { CancelInvoke("OnFire"); return; } if (huoPaoControllerList[currentHuoPaoIndex] == null) { currentHuoPaoIndex++; } if (firePos != null) { firePos.LookAt(huoPaoControllerList[currentHuoPaoIndex].transform.position); GameObject fire = Instantiate(firePrefab); fire.transform.eulerAngles = firePos.eulerAngles; fire.transform.position = firePos.position; fire.GetComponent().SetBoolIsMove(); } //} //fire.transform.LookAt(wrj.transform.localPosition); } }