using System.Collections; using System.Collections.Generic; using UnityEngine; /* */ public class Firelive : MonoBehaviour { //火焰预制体 public GameObject minfire; public GameObject bigfire; //火势值,用于判断火是否灭,是否变大 private float fireNumber=0; //每秒的火势值 public float FireNumber; //判定大火小火的值 public float bigFireNumber; //生成半径 public float spreadRadius; public enum WindDirection { North, South, East, West } public WindDirection windDirection = WindDirection.North; // 风向 private bool isBurning = false; private GameObject currentFire; // 当前生成的火焰实例 public int SpreadFireNumber=1; private bool Canbig = true; // Start is called before the first frame update void Start() { StartBurning(); } // Update is called once per frame void Update() { if (isBurning&&Canbig) { // 检查火势值是否超过阈值 if (fireNumber< bigFireNumber) { fireNumber += FireNumber * Time.deltaTime; return; } SwitchToMaxFire(); } } //火焰初始化 private void StartBurning() { if (!isBurning) { isBurning = true; // 初始在pos位置生成小火焰预制体 currentFire = Instantiate(minfire, transform.position, Quaternion.identity); } } private void SwitchToMaxFire() { // 销毁当前小火焰,替换为大火焰 Destroy(currentFire); currentFire=Instantiate(bigfire, transform.position, Quaternion.identity); Canbig = false; StartCoroutine(DelayedSpread()); } // 延迟蔓延 private IEnumerator DelayedSpread() { // 等待设定的延迟时间 yield return new WaitForSeconds(3); // 开始蔓延火焰 SpreadFireInWindDirection(); } //根据风向改变 private void SpreadFireInWindDirection() { if (SpreadFireNumber<=0) { return; } SpreadFireNumber--; Vector3 spreadDirection = Vector3.zero; // 根据风向设置火焰蔓延的方向 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; } // 获取风向的目标位置 Vector3 targetPosition = transform.position + spreadDirection * spreadRadius; // 在目标位置实例化新的pos Instantiate(gameObject, targetPosition, Quaternion.identity); // GameObject go = Instantiate(gameObject, targetPosition, Quaternion.identity); //go.AddComponent(); } }