Safety Trigger funktioniert wieder, JSON Tool ist im Assets Ordner
This commit is contained in:
@@ -63,6 +63,7 @@ public class GateSpawner : MonoBehaviour
|
||||
public System.Action<bool> OnTutorialQuestionAnswered;
|
||||
public System.Action OnTutorialSequenceFinished;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Fragebild initial aus
|
||||
@@ -455,10 +456,10 @@ public class GateSpawner : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
// === Hilfen ===
|
||||
// === Positionierung des SafetyTriggers > triggert falls Spieler durch kein Gate gefahren ist. Gilt als inkorrekte Antwort. ===
|
||||
private void PlaceSkipTrigger(Transform basis, Vector3 fwd, Vector3 right)
|
||||
{
|
||||
// Finde weitestes Gate (entlang fwd)
|
||||
// === 1) Find farthest gate along 'fwd' ===
|
||||
float maxAlong = float.NegativeInfinity;
|
||||
Vector3 farthestPos = Vector3.zero;
|
||||
|
||||
@@ -474,27 +475,51 @@ public class GateSpawner : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// === 2) Pick trigger position a bit after farthest gate ===
|
||||
Vector3 triggerPos = farthestPos + fwd * skipTriggerOffset;
|
||||
triggerPos = SnapToGround(triggerPos, fallbackGroundY);
|
||||
|
||||
// Height: use ship height if available, otherwise ground
|
||||
float shipY = player ? player.position.y : fallbackGroundY;
|
||||
triggerPos.y = shipY;
|
||||
|
||||
if (activeSkipTrigger != null) { Destroy(activeSkipTrigger); activeSkipTrigger = null; }
|
||||
|
||||
activeSkipTrigger = new GameObject("Safety Trigger");
|
||||
activeSkipTrigger.layer = gameObject.layer;
|
||||
|
||||
// === 3) Safe layer that collides with the ship ===
|
||||
int layer = LayerMask.NameToLayer("Default");
|
||||
activeSkipTrigger.layer = layer;
|
||||
|
||||
activeSkipTrigger.transform.position = triggerPos;
|
||||
activeSkipTrigger.transform.rotation = Quaternion.LookRotation(fwd, Vector3.up);
|
||||
|
||||
var box = activeSkipTrigger.AddComponent<BoxCollider>();
|
||||
box.isTrigger = true;
|
||||
box.size = new Vector3(skipTriggerSize.x, skipTriggerSize.y, skipTriggerThickness);
|
||||
|
||||
// === 4) Size it to cover the whole road (and then some) ===
|
||||
float roadWidth = roadHalfWidth * 2f;
|
||||
float lateralMargin = 300f; // catch off-road flyers
|
||||
float height = 120f; // tall enough regardless of altitude
|
||||
float thickness = Mathf.Max(skipTriggerThickness, 50f); // thick band
|
||||
|
||||
box.size = new Vector3(roadWidth + lateralMargin * 2f, height, thickness);
|
||||
|
||||
// Center vertically on ship height
|
||||
box.center = Vector3.zero; // since we set transform.y to shipY already
|
||||
|
||||
var rb = activeSkipTrigger.AddComponent<Rigidbody>();
|
||||
rb.isKinematic = true; rb.useGravity = false;
|
||||
|
||||
var logic = activeSkipTrigger.AddComponent<SafetyTrigger>();
|
||||
logic.spawner = this;
|
||||
|
||||
// Optional: visual gizmo for sanity (editor only)
|
||||
#if UNITY_EDITOR
|
||||
Debug.Log($"[GateSpawner] Safety Trigger @ {triggerPos} size {box.size}");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Vector3 SnapToGround(Vector3 pos, float fallbackY)
|
||||
{
|
||||
if (groundLayer.value != 0)
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
// SafetyTrigger.cs
|
||||
// Zweck: Sicherheits-Netz: wenn Spieler alle Gates überspringt, wird „falsch“ gezählt und weitergemacht.
|
||||
using UnityEngine;
|
||||
|
||||
public class SafetyTrigger : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string playerTag = "Player";
|
||||
public GateSpawner spawner;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (!other.CompareTag("Player")) return;
|
||||
// Robust root detection (matches GateAnswer approach)
|
||||
Transform root = other.attachedRigidbody
|
||||
? other.attachedRigidbody.transform
|
||||
: other.transform.root;
|
||||
|
||||
if (!root.CompareTag(playerTag)) return;
|
||||
|
||||
// Uncomment while debugging:
|
||||
// Debug.Log($"[SafetyTrigger] Hit by {root.name} (tag {root.tag})");
|
||||
|
||||
spawner?.HandleGateAnswered(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user