using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class SpikeCollision : MonoBehaviour
{
[Header("UI Elements")]
[SerializeField] private GameObject panel;
[SerializeField] private Button restartButton;
private void Awake()
{
if (panel == null)
{
Debug.LogError("Panel is not assigned in the inspector.");
}
if (restartButton == null)
{
Debug.LogError("Restart button is not assigned in the inspector.");
}
}
private void Start()
{
panel.SetActive(false);
restartButton.onClick.AddListener(RestartLevel);
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
ShowPanel();
}
}
private void ShowPanel()
{
panel.SetActive(true);
Time.timeScale = 0;
}
private void RestartLevel()
{
Time.timeScale = 1;
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
private void OnDisable()
{
restartButton.onClick.RemoveListener(RestartLevel);
}
}