using UnityEngine; using System.Collections; public class FallingPlatform : MonoBehaviour { public float fallDelay = 0.5f; // Time before the platform falls public float destroyDelay = 1f; // Time before the platform is destroyed after falling bool isFalling = false; Rigidbody2D rb; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { rb = GetComponent(); } private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Player") && !isFalling) { StartCoroutine(Fall()); } } private IEnumerator Fall() { isFalling = true; yield return new WaitForSeconds(fallDelay); // Wait before falling rb.bodyType = RigidbodyType2D.Dynamic; // Enable physics Destroy(gameObject, destroyDelay); // Destroy the platform } }