56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
// GroundMarkerPulse.cs
|
|
// Zweck: Pulsierender Bodenmarker (Skalierung + optionale Farb/Emission-Pulse).
|
|
using UnityEngine;
|
|
|
|
public class GroundMarkerPulse : MonoBehaviour
|
|
{
|
|
[Header("Scale Pulse")]
|
|
public float minScale = 0.8f;
|
|
public float maxScale = 1.2f;
|
|
public float pulseSpeed = 2f;
|
|
|
|
[Header("Color Pulse (optional)")]
|
|
public Color baseColor = Color.cyan;
|
|
public Color pulseColor = Color.white;
|
|
public float colorPulseStrength = 0.5f; // 0=kein Farb-Puls
|
|
|
|
private Vector3 _initialScale;
|
|
private Material _mat;
|
|
private Color _originalMatColor;
|
|
|
|
private void Start()
|
|
{
|
|
_initialScale = transform.localScale;
|
|
|
|
var renderer = GetComponent<Renderer>();
|
|
if (renderer != null)
|
|
{
|
|
_mat = renderer.material; // eigene Instanz
|
|
_originalMatColor = _mat.color;
|
|
_mat.color = baseColor;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
// Skalenpuls
|
|
float t = (Mathf.Sin(Time.time * pulseSpeed) + 1f) * 0.5f;
|
|
float scaleFactor = Mathf.Lerp(minScale, maxScale, t);
|
|
transform.localScale = new Vector3(
|
|
_initialScale.x * scaleFactor,
|
|
_initialScale.y,
|
|
_initialScale.z * scaleFactor
|
|
);
|
|
|
|
// Farbpuls (optional)
|
|
if (_mat != null && colorPulseStrength > 0f)
|
|
{
|
|
Color target = Color.Lerp(baseColor, pulseColor, t);
|
|
_mat.color = Color.Lerp(baseColor, target, colorPulseStrength);
|
|
|
|
if (_mat.IsKeywordEnabled("_EMISSION"))
|
|
_mat.SetColor("_EmissionColor", target);
|
|
}
|
|
}
|
|
}
|