using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering.Universal; using UnityEngine.SceneManagement; public class AblaufKleinerStern4 : MonoBehaviour { public GameObject wirt; public GameObject maria; public GameObject joseph; public GameObject kleinerStern; public GameObject globalLight; private Action nextStep; private class Task { private Action action; private float time; public Task(Action action, float time){ this.action = action; this.time = time; } public bool isDue(){ return Time.time >= time; } public void Do(){ action(); } } private List taskList; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { taskList = new(); nextStep = AuftrittMariaUndJoseph; globalLight.GetComponent().intensity = 0; wirt.transform.position = new(3.41f, -2.6f); joseph.transform.position = new(-6.8f, -2.81f); maria.transform.position = new(-11.4f, -1.5f); } // Update is called once per frame void Update() { List newlist = new(); foreach (Task t in taskList){ if (t.isDue()){ t.Do(); } else { newlist.Add(t); } } taskList = newlist; if (Input.GetKeyDown(KeyCode.Space) && taskList.Count == 0){ nextStep(); } } private void scheduleNewTask(float timeFromNow, Action action){ Task t = new(action, Time.time + timeFromNow); taskList.Add(t); } private void AuftrittMariaUndJoseph(){ kleinerStern.GetComponent().GoToPosition(new(-5.6f, 3), 0); globalLight.GetComponent().FadeToIntensity(1, 0.5f); joseph.GetComponent().GoToXPosition(-2.64f); maria.GetComponent().GoToXPosition(-7.24f); scheduleNewTask(0.001f, delegate(){ kleinerStern.GetComponent().GoToPositionWithVelocity(new(-3.5f, 3), 1); }); nextStep = AuftrittWirt; } private void AuftrittWirt(){ wirt.GetComponent().GoToXPosition(0.76f); nextStep = SchwenkAufStall; } private void SchwenkAufStall(){ GetComponent().GoToXPosition(-15); transform.rotation = Quaternion.identity; scheduleNewTask(3, delegate(){ kleinerStern.GetComponent().GoToPosition(new(-4, 3), 0); }); nextStep = SternWandert; } private void SternWandert(){ kleinerStern.GetComponent().GoToPositionWithVelocity(new(-16, 3), 2); nextStep = SchwenkZurueck; } private void SchwenkZurueck(){ GetComponent().GoToXPosition(0); nextStep = WirtFuehrtZumStall; } private void WirtFuehrtZumStall(){ wirt.GetComponent().GoToXPosition(-10); scheduleNewTask(3, delegate(){ globalLight.GetComponent().FadeToIntensity(0, 1); }); scheduleNewTask(4.1f, delegate(){ SceneManager.LoadScene("kleiner_Stern_5"); }); nextStep = delegate(){}; } }