intro and start game location
This commit is contained in:
71
Assets/Scripts/LightTransition.cs
Normal file
71
Assets/Scripts/LightTransition.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user