2023-06-11 23:31:54 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
// Kann sein das das nur für statische Objekte funktioniert
|
|
|
|
public class DimShiftBlockable : MonoBehaviour
|
|
|
|
{
|
|
|
|
private GameObject dim1;
|
|
|
|
private GameObject dim2;
|
|
|
|
|
|
|
|
private LinkedList<GameObject> collisions = new LinkedList<GameObject>();
|
2023-06-21 16:13:04 +02:00
|
|
|
|
|
|
|
AudioReverbFilter Rev1;
|
|
|
|
AudioLowPassFilter lpf;
|
|
|
|
GameObject Dim1;
|
|
|
|
GameObject Dim2;
|
|
|
|
|
|
|
|
private Animator animator;
|
2023-06-11 23:31:54 +02:00
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
dim1 = GameObject.Find("Dim1");
|
|
|
|
dim2 = GameObject.Find("Dim2");
|
|
|
|
|
|
|
|
dim1.SetActive(true);
|
|
|
|
dim2.SetActive(false);
|
2023-06-21 16:13:04 +02:00
|
|
|
|
|
|
|
Rev1 = GameObject.Find("AudioController").GetComponent<AudioReverbFilter>();
|
|
|
|
lpf = GameObject.Find("AudioController").GetComponent<AudioLowPassFilter>();
|
|
|
|
|
|
|
|
Rev1.enabled = false;
|
|
|
|
lpf.enabled = false;
|
|
|
|
|
|
|
|
animator = GetComponent<Animator>();
|
2023-06-11 23:31:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (Input.GetKeyDown(KeyCode.LeftShift) && CanSwitchDims())
|
|
|
|
{ // CanSwitchDims ist rel. "teuer", wird aber nur ausgeführt wenn die erste condition true ergibt
|
2023-06-21 16:13:04 +02:00
|
|
|
animator.SetTrigger("ShiftsDim");
|
2023-06-11 23:31:54 +02:00
|
|
|
ChangeDim();
|
2023-06-21 16:13:04 +02:00
|
|
|
MusicSwitch();
|
2023-06-11 23:31:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanSwitchDims()
|
|
|
|
{
|
|
|
|
// eine "günstigere" methode ist mir nicht eingefallen
|
|
|
|
// sollte aber in betracht der länge der liste kein problem sein
|
|
|
|
foreach (var collision in collisions)
|
|
|
|
{
|
|
|
|
if (collision.tag.Equals("DimShiftBlocker")) { return false; }
|
|
|
|
}
|
|
|
|
|
|
|
|
// falls kein dimension shift blocker unter den kollisionen ist, dann yallah abfahrt
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChangeDim()
|
|
|
|
{
|
|
|
|
// invertiert den aktuellen active state der dimensionen
|
|
|
|
// spart die ganzen if statements
|
|
|
|
dim1.SetActive(!dim1.activeSelf);
|
|
|
|
dim2.SetActive(!dim2.activeSelf);
|
|
|
|
}
|
2023-06-21 16:13:04 +02:00
|
|
|
|
|
|
|
void MusicSwitch()
|
|
|
|
{
|
|
|
|
Rev1.enabled = !Rev1.enabled;
|
|
|
|
lpf.enabled = !lpf.enabled;
|
|
|
|
}
|
2023-06-11 23:31:54 +02:00
|
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
|
|
{
|
|
|
|
// addFirst weil on exit die verlassene collision im average case schneller gefunden wird
|
|
|
|
collisions.AddFirst(other.gameObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerExit2D(Collider2D other)
|
|
|
|
{
|
|
|
|
collisions.Remove(other.gameObject);
|
|
|
|
}
|
|
|
|
}
|