81 lines
1.8 KiB
C#
81 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public class npcInit : MonoBehaviour
|
|
{
|
|
[Header("怪物预制体")]
|
|
public GameObject npcPrefab;
|
|
|
|
|
|
[Header("路径")]
|
|
public List<Transform> path = new List<Transform>();
|
|
[Header("移动需要的总时间")]
|
|
public float moveNeedTimer;
|
|
[Header("生成一只怪物的间隔")]
|
|
public float getOneNpcTimer;
|
|
[Header("生成的npc数量")]
|
|
public int npcNumber;
|
|
[Header("迎战按钮")]
|
|
public Button FightBtn;
|
|
|
|
[Header("技能UI")]
|
|
public GameObject JnPanel;
|
|
|
|
private bool isStrat=false;
|
|
|
|
private float timer=0;//计时器
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
FightBtn.onClick.AddListener(() =>
|
|
{
|
|
|
|
FightBtn.gameObject.SetActive(false);
|
|
FightBtn.interactable=false;
|
|
JnPanel.gameObject.SetActive(true);
|
|
isStrat =true;
|
|
|
|
GameObject go = Instantiate(npcPrefab, this.transform);
|
|
go.GetComponent<npcMove>().Init(path, moveNeedTimer);
|
|
go.transform.position = path[0].transform.position;
|
|
|
|
npcNumber--;
|
|
});
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (!isStrat)
|
|
{
|
|
return;
|
|
}
|
|
|
|
timer += Time.deltaTime;
|
|
|
|
if (timer > getOneNpcTimer)
|
|
{
|
|
timer = 0;
|
|
if (npcNumber > 0)
|
|
{
|
|
GameObject go = Instantiate(npcPrefab, this.transform);
|
|
go.GetComponent<npcMove>().Init(path, moveNeedTimer);
|
|
go.transform.position = path[0].transform.position;
|
|
npcNumber--;
|
|
}
|
|
else
|
|
{
|
|
isStrat = false;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|