31 lines
1009 B
C#
31 lines
1009 B
C#
using UnityEngine;
|
|
|
|
namespace SmartRoom
|
|
{
|
|
/// <summary>Lüftungsgerät: Rotor läuft hoch/aus, Luftstrom als Partikel, Status-LED.</summary>
|
|
public class VentilationActuator : MonoBehaviour
|
|
{
|
|
[Range(0, 1)] public float target;
|
|
public float speed = 0.4f;
|
|
public float maxRpmDegrees = 900f;
|
|
public Transform rotor;
|
|
public ParticleSystem air;
|
|
public Material led;
|
|
|
|
public float Current { get; private set; }
|
|
|
|
static readonly Color LedOn = new Color(0.16f, 0.85f, 0.85f);
|
|
|
|
void Update()
|
|
{
|
|
Current = Mathf.MoveTowards(Current, target, speed * Time.deltaTime);
|
|
rotor.Rotate(0f, Current * maxRpmDegrees * Time.deltaTime, 0f, Space.Self);
|
|
var em = air.emission;
|
|
em.rateOverTime = 70f * Current;
|
|
var main = air.main;
|
|
main.startSpeed = 0.4f + 1.0f * Current;
|
|
Mat.SetEmission(led, Current > 0.02f ? LedOn * 2f : Color.black);
|
|
}
|
|
}
|
|
}
|