Files
Crash-Course/Assets/Scripts/Game/ObstacleCourse.cs

33 lines
1.0 KiB
C#
Raw Normal View History

2025-04-18 15:54:50 -04:00
using UnityEngine;
using Game;
using Music;
using Player;
2025-04-16 19:57:54 -04:00
namespace Game
{
2025-04-18 15:54:50 -04:00
/// <summary>
/// This class handles the logic for detecting when a player completes the obstacle course.
/// </summary>
public class ObstacleCourse : MonoBehaviour
2025-03-31 18:28:05 -04:00
{
2025-04-18 15:54:50 -04:00
/// <summary>
/// The player who successfully completes the obstacle course.
/// </summary>
public static GameObject playerWon;
/// <summary>
/// Detects when a player enters the trigger area and ends the game.
/// </summary>
/// <param name="collision">The collider of the object that entered the trigger.</param>
private void OnTriggerEnter2D(Collider2D collision)
2025-03-31 18:28:05 -04:00
{
2025-04-18 15:54:50 -04:00
// Check if the object entering the trigger is a player
if (collision.gameObject.CompareTag("Player"))
{
// Set the player who won and trigger the game over logic
playerWon = collision.gameObject;
GameManager.Instance.GameOver();
}
2025-03-31 18:28:05 -04:00
}
}
2025-04-16 19:57:54 -04:00
}