using Ktyl.Util; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class FallawayFloor : MonoBehaviour { // Speed at which the object moves towards the ground. public float speed; // Time it takes for ogjecct to begin moving towards the ground. public float fallAwayTime; // Time taken for object to be destroyed. public float destroyObjectTime; public Material dissolve; [SerializeField] private Renderer _renderer; [SerializeField] private SerialFloat objectTimeScale; Rigidbody rb; private void Start() { // Get Rigidbody component. rb = GetComponent(); } private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { // Start the Destroy floor coroutine and switch to the dissolve material. if (objectTimeScale != 0) { StartCoroutine(DestroyFloor()); _renderer.material = dissolve; } } } //The platform gets destroyed after the player resumes frozen time on a platform private void OnTriggerStay(Collider other) { if (other.CompareTag("Player")) { // Start the Destroy floor coroutine and switch to the dissolve material. if (objectTimeScale != 0) { StartCoroutine(DestroyFloor()); _renderer.material = dissolve; } } } IEnumerator DestroyFloor() { // Take fallAwayTime, speed, and destroyObjectTime from editor and apply yield return new WaitForSeconds(fallAwayTime); rb.velocity = Vector3.down * speed; yield return new WaitForSeconds(destroyObjectTime); Destroy(gameObject); } }