Neues DimShift Skript welches Block-Zonen haben kann
This commit is contained in:
parent
824ce7eac8
commit
1f55a68b17
60
Assets/AssetsFORELLE/Script/DimShiftBlockable.cs
Normal file
60
Assets/AssetsFORELLE/Script/DimShiftBlockable.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
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>();
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
dim1 = GameObject.Find("Dim1");
|
||||||
|
dim2 = GameObject.Find("Dim2");
|
||||||
|
|
||||||
|
dim1.SetActive(true);
|
||||||
|
dim2.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (Input.GetKeyDown(KeyCode.LeftShift) && CanSwitchDims())
|
||||||
|
{ // CanSwitchDims ist rel. "teuer", wird aber nur ausgeführt wenn die erste condition true ergibt
|
||||||
|
ChangeDim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
3
Assets/AssetsFORELLE/Script/DimShiftBlockable.cs.meta
generated
Normal file
3
Assets/AssetsFORELLE/Script/DimShiftBlockable.cs.meta
generated
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7f029a553bbe434cac37e668d41d7ea9
|
||||||
|
timeCreated: 1686511019
|
Loading…
x
Reference in New Issue
Block a user