92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
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<Task> 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<Light2D>().intensity = 0;
|
|
grosserSternLicht.GetComponent<Light2D>().intensity = 0;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
List<Task> 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<Lichtsteuerung>().FadeToIntensity(1, 2);
|
|
nextStep = HirtenKommen;
|
|
}
|
|
|
|
private void HirtenKommen(){
|
|
grosserSternLicht.GetComponent<Lichtsteuerung>().FadeToIntensity(1, 7);
|
|
scheduleNewTask(4, delegate(){
|
|
hirt1.GetComponent<FigurMitBeinenBewegung>().GoToXPosition(targetHirt1);
|
|
hirt2.GetComponent<FigurMitBeinenBewegung>().GoToXPosition(targetHirt2);
|
|
grosserStern.GetComponent<SternBewegung>().GoToPositionWithVelocity(new(targetGrosserStern, 3.14f), 1);
|
|
});
|
|
nextStep = Ende;
|
|
}
|
|
|
|
private void Ende(){
|
|
grosserSternLicht.GetComponent<Lichtsteuerung>().FadeToIntensity(0, 2.5f);
|
|
kleinerStern.GetComponent<Lichtsteuerung>().FadeToIntensity(0, 2.5f);
|
|
nextStep = delegate(){};
|
|
}
|
|
}
|