62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class HuoPaoController : MonoBehaviour
|
|
{
|
|
public GameObject wrj;
|
|
public List<GameObject> wrjs = new List<GameObject>();
|
|
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<BulletController>().huoPaoController = this;
|
|
fire.GetComponent<BulletController>().SetBoolIsMove();
|
|
//fire.transform.LookAt(wrj.transform.localPosition);
|
|
}
|
|
}
|
|
}
|