using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class CrushingBoulder : MonoBehaviour
|
|
{
|
|
public bool triggeranimate;
|
|
public bool triggeranimate1;
|
|
public int countdowntimer;
|
|
public TextMeshPro counter;
|
|
int countdown;
|
|
|
|
private void Start()
|
|
{
|
|
countdown = countdowntimer;
|
|
}
|
|
private void Update()
|
|
{
|
|
counter.text = countdown.ToString();
|
|
}
|
|
|
|
IEnumerator FallRaiseCoroutine(float dropDistance)
|
|
{
|
|
float elapsedTime = 0;
|
|
Vector3 startPosition = transform.position;
|
|
Vector3 endPosition = new Vector3(transform.position.x, transform.position.y + dropDistance, transform.position.z);
|
|
float time = 0.8f;
|
|
while (elapsedTime < time)
|
|
{
|
|
transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
|
|
yield return new WaitForEndOfFrame();
|
|
elapsedTime += Time.deltaTime;
|
|
}
|
|
transform.position = endPosition;
|
|
}
|
|
|
|
public void Animate()
|
|
{
|
|
countdown--;
|
|
if (countdown == 0)
|
|
{
|
|
StartCoroutine(FallRaiseCoroutine(-2.0f));
|
|
countdown = countdowntimer;
|
|
returnToPosition();
|
|
}
|
|
}
|
|
public void returnToPosition()
|
|
{
|
|
StartCoroutine(FallRaiseCoroutine(2.0f));
|
|
}
|
|
}
|