You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. public class CrushingBoulder : MonoBehaviour
  6. {
  7. public bool triggeranimate;
  8. public bool triggeranimate1;
  9. public int countdowntimer;
  10. public TextMeshPro counter;
  11. int countdown;
  12. private void Start()
  13. {
  14. countdown = countdowntimer;
  15. }
  16. private void Update()
  17. {
  18. counter.text = countdown.ToString();
  19. }
  20. IEnumerator FallRaiseCoroutine(float dropDistance)
  21. {
  22. float elapsedTime = 0;
  23. Vector3 startPosition = transform.position;
  24. Vector3 endPosition = new Vector3(transform.position.x, transform.position.y + dropDistance, transform.position.z);
  25. float time = 0.8f;
  26. while (elapsedTime < time)
  27. {
  28. transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  29. yield return new WaitForEndOfFrame();
  30. elapsedTime += Time.deltaTime;
  31. }
  32. transform.position = endPosition;
  33. }
  34. public void Animate()
  35. {
  36. countdown--;
  37. if (countdown == 0)
  38. {
  39. StartCoroutine(FallRaiseCoroutine(-2.0f));
  40. countdown = countdowntimer;
  41. returnToPosition();
  42. }
  43. }
  44. public void returnToPosition()
  45. {
  46. StartCoroutine(FallRaiseCoroutine(2.0f));
  47. }
  48. }