66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
|
||
using UnityEngine;
|
||
|
||
public class Fire : MonoBehaviour
|
||
{
|
||
[Header("0为硬火,1为软火")]
|
||
[Range(0, 1)] public float Value;
|
||
|
||
public ParticleSystem fireBig;
|
||
public ParticleSystem fireSmall;
|
||
|
||
public Vector2 LifeTime;
|
||
|
||
public Vector2 Size;
|
||
|
||
public Vector2 Gravity;
|
||
|
||
public Vector2 Count;
|
||
|
||
public Color mainColor;
|
||
|
||
private ParticleSystem.MainModule big;
|
||
private ParticleSystem.MainModule small;
|
||
|
||
ParticleSystem.SizeOverLifetimeModule bigSize;
|
||
ParticleSystem.SizeOverLifetimeModule smallSize;
|
||
|
||
private ParticleSystem.EmissionModule smallemission;
|
||
|
||
private ParticleSystem.MinMaxCurve curr;
|
||
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
big = fireBig.main;
|
||
small = fireSmall.main;
|
||
|
||
bigSize = fireBig.sizeOverLifetime;
|
||
smallSize = fireSmall.sizeOverLifetime;
|
||
|
||
smallemission=fireSmall.emission;
|
||
|
||
curr = new ParticleSystem.MinMaxCurve();
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
big.startColor = Color.Lerp(mainColor, Color.white, Value);
|
||
big.startLifetime = Mathf.Lerp(LifeTime.x,LifeTime.y,Value);
|
||
small.startLifetime = Mathf.Lerp(LifeTime.x,LifeTime.y,Value);
|
||
|
||
big.startSize = Mathf.Lerp(Size.x,Size.y,Value);
|
||
small.startSize = Mathf.Lerp(Size.x,Size.y,Value);
|
||
|
||
big.gravityModifier = Mathf.Lerp(Gravity.x,Gravity.y,Value);
|
||
small.gravityModifier = Mathf.Lerp(Gravity.x,Gravity.y,Value);
|
||
curr = new ParticleSystem.MinMaxCurve(1,
|
||
AnimationCurve.EaseInOut(0, Mathf.Lerp(1, 0.3f, Value), 1, Mathf.Lerp(0.3f, 1, Value)));
|
||
bigSize.size = curr;
|
||
smallSize.size = curr;
|
||
smallemission.rateOverTime=Mathf.Lerp(Count.x,Count.y,Value);
|
||
|
||
}
|
||
}
|