mycj_demo/mycj/Assets/Script/npcInit.cs

81 lines
1.8 KiB
C#
Raw Normal View History

2024-12-02 09:37:47 +08:00
using System.Collections;
using System.Collections.Generic;
2024-12-02 23:38:32 +08:00
using System.Threading.Tasks;
2024-12-02 09:37:47 +08:00
using UnityEngine;
2024-12-02 23:38:32 +08:00
using UnityEngine.UI;
2024-12-02 09:37:47 +08:00
public class npcInit : MonoBehaviour
{
2024-12-02 23:38:32 +08:00
[Header("<22><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>")]
2024-12-02 09:37:47 +08:00
public GameObject npcPrefab;
[Header("·<><C2B7>")]
public List<Transform> path = new List<Transform>();
2024-12-02 23:38:32 +08:00
[Header("<22>ƶ<EFBFBD><C6B6><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>")]
2024-12-02 09:37:47 +08:00
public float moveNeedTimer;
2024-12-02 23:38:32 +08:00
[Header("<22><><EFBFBD><EFBFBD>һֻ<D2BB><D6BB><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>")]
public float getOneNpcTimer;
[Header("<22><><EFBFBD>ɵ<EFBFBD>npc<70><63><EFBFBD><EFBFBD>")]
public int npcNumber;
[Header("ӭս<D3AD><D5BD>ť")]
public Button FightBtn;
[Header("<22><><EFBFBD><EFBFBD>UI")]
public GameObject JnPanel;
private bool isStrat=false;
private float timer=0;//<2F><>ʱ<EFBFBD><CAB1>
2024-12-02 09:37:47 +08:00
// Start is called before the first frame update
void Start()
{
2024-12-02 23:38:32 +08:00
FightBtn.onClick.AddListener(() =>
{
2024-12-02 09:37:47 +08:00
2024-12-02 23:38:32 +08:00
FightBtn.gameObject.SetActive(false);
FightBtn.interactable=false;
JnPanel.gameObject.SetActive(true);
isStrat =true;
2024-12-02 09:37:47 +08:00
2024-12-02 23:38:32 +08:00
GameObject go = Instantiate(npcPrefab, this.transform);
go.GetComponent<npcMove>().Init(path, moveNeedTimer);
go.transform.position = path[0].transform.position;
2024-12-02 09:37:47 +08:00
2024-12-02 23:38:32 +08:00
npcNumber--;
});
2024-12-02 09:37:47 +08:00
}
2024-12-02 23:38:32 +08:00
// Update is called once per frame
void Update()
2024-12-02 09:37:47 +08:00
{
2024-12-02 23:38:32 +08:00
if (!isStrat)
2024-12-02 09:37:47 +08:00
{
2024-12-02 23:38:32 +08:00
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;
}
2024-12-02 09:37:47 +08:00
}
}
2024-12-02 23:38:32 +08:00
2024-12-02 09:37:47 +08:00
}