using UnityEngine;
using Game;
using Music;
using Player;
namespace Game
{
///
/// This class handles respawning objects when they collide with a trigger tagged with a specific value.
///
public class RespawnOnTriggerEnter : MonoBehaviour
{
///
/// The spawn point where the object will respawn.
///
public Vector2 spawnPoint;
///
/// If true, the spawn point is set to the object's initial position.
///
public bool spawnPointIsInitialPosition = false;
///
/// The tag of the trigger that causes the object to respawn.
///
public string respawnTag;
///
/// Sets the spawn point to the object's initial position if specified.
///
private void Start()
{
if (spawnPointIsInitialPosition)
{
// Set the spawn point to the object's initial position
spawnPoint = transform.position;
}
}
///
/// Handles collisions with triggers and applies damage to the object if it has a component.
///
/// The collider of the object that entered the trigger.
private void OnTriggerEnter2D(Collider2D other)
{
// Check if the collider has the specified tag
if (other.CompareTag(respawnTag))
{
// Apply damage to the object if it has a Damageable component
if (TryGetComponent(out Damageable damageable))
{
damageable.Damage(9999f);
}
}
}
}
}