69 lines
1.5 KiB
C#
69 lines
1.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Ktyl.Util;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(Rigidbody))]
|
|
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;
|
|
public Material dissolve;
|
|
|
|
[SerializeField] private Renderer _renderer;
|
|
[SerializeField] private TrapSettings _settings;
|
|
|
|
private Rigidbody rb;
|
|
private Vector3 initialPosition;
|
|
private bool _triggered = false;
|
|
|
|
private void Start()
|
|
{
|
|
initialPosition = transform.position;
|
|
|
|
// Get Rigidbody component.
|
|
rb = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (!_triggered) return;
|
|
|
|
if (_settings.FallawayFloor.CanRespawn)
|
|
{
|
|
Reset();
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!_triggered && other.CompareTag("Player"))
|
|
{
|
|
StartCoroutine(Fall());
|
|
}
|
|
}
|
|
|
|
private IEnumerator Fall()
|
|
{
|
|
// TODO: trigger shake, maybe particle effect?
|
|
|
|
_triggered = true;
|
|
|
|
// wait a moment
|
|
yield return new WaitForSeconds(fallAwayTime);
|
|
|
|
// fall
|
|
rb.velocity = Vector3.down * speed;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
_triggered = false;
|
|
transform.position = initialPosition;
|
|
rb.velocity = Vector3.zero;
|
|
}
|
|
}
|