2025-02-28 17:46:02 -05:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class TeleportPlatform : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Vector2 teleportPoint;
|
|
|
|
|
public string teleportTag;
|
2025-03-03 11:58:00 -05:00
|
|
|
public string playerTag = "Player";
|
|
|
|
|
public bool isPlatform = true;
|
2025-02-28 17:46:02 -05:00
|
|
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
|
{
|
2025-03-03 11:58:00 -05:00
|
|
|
if (!isPlatform)
|
|
|
|
|
{
|
2025-03-28 17:39:07 -04:00
|
|
|
// Teleports the platform
|
2025-03-03 11:58:00 -05:00
|
|
|
if (collision.CompareTag(teleportTag))
|
|
|
|
|
{
|
|
|
|
|
transform.position = teleportPoint;
|
|
|
|
|
if (TryGetComponent<Rigidbody2D>(out var rb))
|
|
|
|
|
{
|
|
|
|
|
rb.linearVelocity = Vector2.zero;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2025-02-28 17:46:02 -05:00
|
|
|
{
|
2025-03-28 17:39:07 -04:00
|
|
|
// Teleports the player
|
2025-03-03 11:58:00 -05:00
|
|
|
if (collision.CompareTag(playerTag))
|
2025-02-28 17:46:02 -05:00
|
|
|
{
|
2025-03-03 11:58:00 -05:00
|
|
|
collision.transform.position = teleportPoint;
|
|
|
|
|
if (collision.TryGetComponent<Rigidbody2D>(out var rb))
|
|
|
|
|
{
|
|
|
|
|
rb.linearVelocity = Vector2.zero;
|
|
|
|
|
}
|
2025-02-28 17:46:02 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|