MiniGames/Assets/Scripts/SkyWalker/Skywalker_Obstacle.cs

36 lines
953 B
C#
Raw Normal View History

2025-09-01 00:01:33 +05:00
using UnityEngine;
[RequireComponent(typeof(Collider))]
public class Skywalker_Obstacle : MonoBehaviour
{
[Header("Obstacle Settings")]
public bool destroyOnContact = false; // if true, obstacle is removed after hit
private void Reset()
{
// Make sure obstacle collider is set properly
Collider col = GetComponent<Collider>();
if (col != null)
col.isTrigger = true; // obstacle works as trigger zone
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Debug.Log("Player hit an obstacle!");
// Trigger game over through GameManager
if (Skywalker_GameManager.Instance != null)
{
2025-09-22 17:26:19 +05:00
Skywalker_GameManager.Instance.TriggerGameOver(DeathType.Normal);
2025-09-01 00:01:33 +05:00
}
if (destroyOnContact)
{
Destroy(gameObject);
}
}
}
}