_xiaofang/xiaofang/Assets/Script/Item/Firelive.cs

135 lines
3.2 KiB
C#
Raw Normal View History

2024-10-22 17:31:48 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
2024-10-22 17:31:48 +08:00
2024-10-23 11:29:08 +08:00
/*
*/
2024-10-22 17:31:48 +08:00
public class Firelive : MonoBehaviour
{
2024-10-23 11:29:08 +08:00
//<2F><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
public GameObject minfire;
public GameObject bigfire;
//<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϻ<D0B6><CFBB>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
private float fireNumber=0;
//ÿ<><C3BF><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>ֵ
public float FireNumber;
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>ֵ
public float bigFireNumber;
//<2F><><EFBFBD>ɰ뾶
public float spreadRadius;
public enum WindDirection { North, South, East, West }
public WindDirection windDirection = WindDirection.North; // <20><><EFBFBD><EFBFBD>
private bool isBurning = false;
private GameObject currentFire; // <20><>ǰ<EFBFBD><C7B0><EFBFBD>ɵĻ<C9B5><C4BB><EFBFBD>ʵ<EFBFBD><CAB5>
public int SpreadFireNumber=1;
private bool Canbig = true;
public Text time;
2024-10-22 17:31:48 +08:00
// Start is called before the first frame update
void Start()
{
2024-10-23 11:29:08 +08:00
StartBurning();
time.gameObject.SetActive(false);
2024-10-22 17:31:48 +08:00
}
2024-10-24 09:23:47 +08:00
2024-10-22 17:31:48 +08:00
// Update is called once per frame
void Update()
{
2024-10-23 11:29:08 +08:00
if (isBurning&&Canbig)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Ƿ񳬹<C7B7><F1B3ACB9><EFBFBD>ֵ
if (fireNumber< bigFireNumber)
{
fireNumber += FireNumber * Time.deltaTime;
return;
}
SwitchToMaxFire();
}
2024-10-22 17:31:48 +08:00
}
2024-10-23 11:29:08 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
private void StartBurning()
{
if (!isBurning)
{
isBurning = true;
// <20><>ʼ<EFBFBD><CABC>posλ<73><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
2024-10-23 15:13:58 +08:00
currentFire = Instantiate(minfire, transform.position, Quaternion.identity);
2024-10-24 09:23:47 +08:00
2024-10-23 11:29:08 +08:00
}
}
private void SwitchToMaxFire()
{
// <20><><EFBFBD>ٵ<EFBFBD>ǰС<C7B0><D0A1><EFBFBD><EFBFBD>滻Ϊ<E6BBBB><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Destroy(currentFire);
currentFire=Instantiate(bigfire, transform.position, Quaternion.identity);
Canbig = false;
currentFire.GetComponent<Fire>().TimeText = time;
2024-10-23 11:29:08 +08:00
StartCoroutine(DelayedSpread());
}
// <20>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD>
private IEnumerator DelayedSpread()
{
// <20>ȴ<EFBFBD><C8B4><EFBFBD><E8B6A8><EFBFBD>ӳ<EFBFBD>ʱ<EFBFBD><CAB1>
yield return new WaitForSeconds(3);
// <20><>ʼ<EFBFBD><CABC><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>
SpreadFireInWindDirection();
}
//<2F><><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD>ı<EFBFBD>
private void SpreadFireInWindDirection()
{
if (SpreadFireNumber<=0)
{
return;
}
SpreadFireNumber--;
Vector3 spreadDirection = Vector3.zero;
// <20><><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵķ<D3B5><C4B7><EFBFBD>
switch (windDirection)
{
case WindDirection.North:
spreadDirection = Vector3.forward;
break;
case WindDirection.South:
spreadDirection = Vector3.back;
break;
case WindDirection.East:
spreadDirection = Vector3.right;
break;
case WindDirection.West:
spreadDirection = Vector3.left;
break;
}
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>
Vector3 targetPosition = transform.position + spreadDirection * spreadRadius;
// <20><>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>pos
Instantiate(gameObject, targetPosition, Quaternion.identity);
// GameObject go = Instantiate(gameObject, targetPosition, Quaternion.identity);
//go.AddComponent<Firelive>();
}
2024-10-22 17:31:48 +08:00
}