revival/game/Assets/Scripts/Traps/FallawayFloor.cs

35 lines
745 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FallawayFloor : MonoBehaviour
{
public float speed;
public Material dissolve;
Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
StartCoroutine(DestroyFloor());
GetComponent<Renderer>().material = dissolve;
}
}
IEnumerator DestroyFloor()
{
yield return new WaitForSeconds(1f);
rb.velocity = Vector3.down * speed;
yield return new WaitForSeconds(1);
Destroy(gameObject);
yield return null;
}
}