using UnityEngine; using System.Collections; public class LightTransition : MonoBehaviour { [Header("Ustawienia Światła")] [Tooltip("Przeciągnij tutaj światło Directional Light, którym chcesz sterować.")] public Light directionalLight; [Header("Wartości Docelowe")] [Tooltip("Docelowa rotacja światła (w stopniach).")] public Vector3 targetRotationEuler; [Tooltip("Docelowy kolor światła.")] public Color targetColor = Color.white; [Tooltip("Docelowa intensywność światła.")] [Range(0f, 8f)] public float targetIntensity = 1f; [Header("Ustawienia Przejścia")] [Tooltip("Czas trwania przejścia w sekundach.")] public float transitionDuration = 5.0f; // Uruchamia przejście public void StartLightTransition() { StopAllCoroutines(); StartCoroutine(TransitionRoutine()); } private IEnumerator TransitionRoutine() { // 1. Zapisujemy wartości początkowe Quaternion initialRotation = directionalLight.transform.rotation; Color initialColor = directionalLight.color; float initialIntensity = directionalLight.intensity; Quaternion targetRotation = Quaternion.Euler(targetRotationEuler); float elapsedTime = 0f; // 2. Pętla przejścia while (elapsedTime < transitionDuration) { float progress = elapsedTime / transitionDuration; // 3. Interpolacja wszystkich wartości jednocześnie directionalLight.transform.rotation = Quaternion.Slerp(initialRotation, targetRotation, progress); directionalLight.color = Color.Lerp(initialColor, targetColor, progress); // POPRAWIONA LINIA directionalLight.intensity = Mathf.Lerp(initialIntensity, targetIntensity, progress); elapsedTime += Time.deltaTime; yield return null; } // 4. Ustawienie wartości końcowych dla pewności directionalLight.transform.rotation = targetRotation; directionalLight.color = targetColor; directionalLight.intensity = targetIntensity; } // Opcjonalnie: Trigger do uruchamiania eventu private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { Debug.Log("Gracz wszedł w trigger. Uruchamiam zmianę światła!"); StartLightTransition(); } } }