using System.Collections; using System.Collections.Generic; using UnityEngine; public class HuoPaoController : MonoBehaviour { public GameObject wrj; public List wrjs = new List(); public float dis; public float limitDis; public Transform firePos; public GameObject firePrefab; // Start is called before the first frame update void Start() { InvokeRepeating("OnFire", 3, 3); } // Update is called once per frame void Update() { for (int i = 0; i < wrjs.Count; i++) { if (wrjs[i] != null) { dis = Vector3.Distance(wrjs[i].transform.localPosition, firePos.localPosition); if (Vector3.Distance(wrjs[i].transform.localPosition, firePos.localPosition) < limitDis) { if (wrj == null) { wrj = wrjs[i]; } return; } else { wrj = null; } } } } private void OnFire() { if (wrj != null) { if (wrjs.Count == 0) { CancelInvoke("OnFire"); return; } firePos.LookAt(wrj.transform.position); GameObject fire = Instantiate(firePrefab); fire.transform.eulerAngles = firePos.eulerAngles; fire.transform.position = firePos.position; fire.GetComponent().huoPaoController = this; fire.GetComponent().SetBoolIsMove(); //fire.transform.LookAt(wrj.transform.localPosition); } } }