Files
Crash-Course/Assets/Scripts/FallPlatform.cs
TGall8 47314da759 Created new map for free-for-all mode
Platform3 (MOUNTAIN) is the new map. I tried to fix the FallPlatform script so falling platforms would respawn but I didn't get anywhere. Will try again later
2025-03-05 21:08:52 -05:00

42 lines
985 B
C#

using System.Collections;
using UnityEngine;
public class FallPlatform : MonoBehaviour
{
public float fallDelay = 2f;
public float resetDelay = 2f;
bool falling;
Rigidbody2D rb;
//Transform defposition;
void Start()
{
//defposition = gameObject.transform;
rb = transform.parent.GetComponent<Rigidbody2D>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (!falling/* && collision.gameObject.CompareTag("Player")*/)
{
StartCoroutine(FallAfterDelay());
}
}
private IEnumerator FallAfterDelay()
{
falling = true;
yield return new WaitForSeconds(fallDelay);
rb.bodyType = RigidbodyType2D.Dynamic;
yield return new WaitForSeconds(resetDelay);
//Respawn();
}
//private void Respawn()
//{
//rb.bodyType = RigidbodyType2D.Static;
//gameObject.transform.position = defposition.position;
//}
}