using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering.Universal; public class AblaufKleinerStern6 : MonoBehaviour { public GameObject kleinerStern; public GameObject grosserStern; public GameObject grosserSternLicht; public GameObject hirt1; public GameObject hirt2; 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 = KleinerSternWachtAuf; grosserStern.transform.position = new(targetGrosserStern - distanceHirten, 3.14f); hirt1.transform.position = new(targetHirt1 - distanceHirten, -2.08f); hirt2.transform.position = new(targetHirt2 - distanceHirten, -2.31f); kleinerStern.GetComponent().intensity = 0; grosserSternLicht.GetComponent().intensity = 0; } // 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 const float targetHirt1 = -3.46f; private const float targetHirt2 = -6.68f; private const float targetGrosserStern = -0.37f; private const float distanceHirten = 12; private void KleinerSternWachtAuf(){ kleinerStern.GetComponent().FadeToIntensity(1, 2); nextStep = HirtenKommen; } private void HirtenKommen(){ grosserSternLicht.GetComponent().FadeToIntensity(1, 7); scheduleNewTask(4, delegate(){ hirt1.GetComponent().GoToXPosition(targetHirt1); hirt2.GetComponent().GoToXPosition(targetHirt2); grosserStern.GetComponent().GoToPositionWithVelocity(new(targetGrosserStern, 3.14f), 1); }); nextStep = Ende; } private void Ende(){ grosserSternLicht.GetComponent().FadeToIntensity(0, 2.5f); kleinerStern.GetComponent().FadeToIntensity(0, 2.5f); nextStep = delegate(){}; } }