Files
Crash-Course/Assets/Scripts/FallPlatform.cs
TGall8 8543734eb9 Added moving and teleporting platforms in ObstanceWIP. Falling Platform is a WIP
Falling Platforms don't work yet. Still haven't figured out how to make it fall
2025-02-28 17:46:02 -05:00

32 lines
695 B
C#

using System.Collections;
using UnityEngine;
public class FallPlatform : MonoBehaviour
{
public float fallDelay = 2f;
public float destroyDelay = 2f;
bool falling;
Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void OnCollisionEnter2D(Collider2D collision)
{
if (!falling && collision.gameObject.CompareTag("Player"))
{
StartCoroutine(FallAfterDelay());
}
}
private IEnumerator FallAfterDelay()
{
falling = true;
yield return new WaitForSeconds(fallDelay);
rb.bodyType = RigidbodyType2D.Dynamic;
Destroy(gameObject, destroyDelay);
}
}