29 lines
1021 B
C#
29 lines
1021 B
C#
using UnityEngine;
|
|
|
|
namespace SmartRoom
|
|
{
|
|
/// <summary>Heizkörper: glüht je nach Leistung warm auf, aufsteigende Wärme als Partikel.</summary>
|
|
public class HeaterActuator : MonoBehaviour
|
|
{
|
|
[Range(0, 1)] public float target;
|
|
[Tooltip("Thermische Trägheit")] public float speed = 0.08f;
|
|
public Material finMaterial;
|
|
public ParticleSystem heatFx;
|
|
|
|
public float Current { get; private set; }
|
|
|
|
static readonly Color Cold = new Color(0.93f, 0.93f, 0.92f);
|
|
static readonly Color Warm = new Color(1f, 0.5f, 0.3f);
|
|
|
|
void Update()
|
|
{
|
|
Current = Mathf.MoveTowards(Current, target, speed * Time.deltaTime);
|
|
float glow = Current * (0.85f + 0.15f * Mathf.Sin(Time.time * 2.2f));
|
|
Mat.SetColor(finMaterial, Color.Lerp(Cold, Warm, Current * 0.55f));
|
|
Mat.SetEmission(finMaterial, Warm * (glow * 0.45f));
|
|
var em = heatFx.emission;
|
|
em.rateOverTime = 14f * Current;
|
|
}
|
|
}
|
|
}
|