campfire/Assets/Scripts/Flame.cs
2020-04-19 23:22:24 +03:00

38 lines
955 B
C#

#pragma warning disable CS0618
using UnityEngine;
[ExecuteAlways]
public class Flame : MonoBehaviour {
[Range(0, 1)]
public float Aliveness = 1;
public ParticleSystem System;
public float AddFuelEffect;
private float SecretBoost = 0f;
// Start is called before the first frame update
void Start() {
}
// Update is called once per frame
void Update() {
if (AddFuelEffect > 0f) {
SecretBoost += 0.2f / (SecretBoost + 0.2f) * 2f * AddFuelEffect;
AddFuelEffect = 0f;
}
if (SecretBoost > 0) {
SecretBoost -= Time.deltaTime * 3;
}
float TotalAliveness = Aliveness + Mathf.Max(SecretBoost, 0);
System.startLifetime = 1.2f + 1.8f * Aliveness;
var em = System.emission;
em.rateOverTime = 20 + 80 * TotalAliveness;
var vol = System.velocityOverLifetime;
vol.radial = 0.7f * TotalAliveness;
}
}