Hi, In this video I will show how to create platform that falls after player will jump on it.
Link to video:
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FallingPlatform : MonoBehaviour
{
public float TimeUntilFall;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
Invoke("Fall", TimeUntilFall);
}
}
public void Fall()
{
if (gameObject.GetComponent<Rigidbody2D>() != null)
{
gameObject.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
}
}
}