using System.Collections; using System.Collections.Generic; using UnityEngine; public class CrushingBoulder : MonoBehaviour { public bool triggeranimate; public bool triggeranimate1; private void Update() { //for testing purposes if (triggeranimate == true) { Animate(); triggeranimate = false; } if (triggeranimate1 == true) { returnToPosition(); triggeranimate1 = false; } } 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() { StartCoroutine(FallRaiseCoroutine(-2.0f)); } public void returnToPosition() { StartCoroutine(FallRaiseCoroutine(2.0f)); } }