using UnityEngine; using Game; using Music; using Player; namespace Player { /// /// This class handles teleportation for platforms and players when they collide with the teleport trigger. /// It can teleport either the platform itself or a player to a specified location. /// public class TeleportPlatform : MonoBehaviour { /// /// The position where the platform or player will be teleported. /// public Vector2 teleportPoint; /// /// The tag used to identify objects (e.g., platforms) that can trigger teleportation. /// public string teleportTag; /// /// The tag used to identify player objects. /// public string playerTag = "Player"; /// /// Determines whether this script is handling a platform or a player. /// If true, it teleports players. If false, it teleports the platform itself. /// public bool isPlatform = true; /// /// Handles the teleportation logic when an object enters the trigger collider. /// /// The collider of the object that entered the trigger. private void OnTriggerEnter2D(Collider2D collision) { if (!isPlatform) { // Teleports the platform itself if (collision.CompareTag(teleportTag)) { // Move the platform to the teleport point transform.position = teleportPoint; // Reset the platform's velocity if it has a Rigidbody2D component if (TryGetComponent(out var rb)) { rb.linearVelocity = Vector2.zero; } } } else { // Teleports the player if (collision.CompareTag(playerTag)) { // Move the player to the teleport point collision.transform.position = teleportPoint; // Reset the player's velocity if they have a Rigidbody2D component if (collision.TryGetComponent(out var rb)) { rb.linearVelocity = Vector2.zero; } } } } } }