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.

63 lines
1.6 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. //for testing purposes
  20. if (triggeranimate == true)
  21. {
  22. Animate();
  23. triggeranimate = false;
  24. }
  25. if (triggeranimate1 == true)
  26. {
  27. returnToPosition();
  28. triggeranimate1 = false;
  29. }
  30. }
  31. IEnumerator FallRaiseCoroutine(float dropDistance)
  32. {
  33. float elapsedTime = 0;
  34. Vector3 startPosition = transform.position;
  35. Vector3 endPosition = new Vector3(transform.position.x, transform.position.y + dropDistance, transform.position.z);
  36. float time = 0.8f;
  37. while (elapsedTime < time)
  38. {
  39. transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  40. yield return new WaitForEndOfFrame();
  41. elapsedTime += Time.deltaTime;
  42. }
  43. transform.position = endPosition;
  44. }
  45. public void Animate()
  46. {
  47. countdown--;
  48. if (countdown == 0)
  49. {
  50. StartCoroutine(FallRaiseCoroutine(-2.0f));
  51. countdown = countdowntimer;
  52. returnToPosition();
  53. }
  54. }
  55. public void returnToPosition()
  56. {
  57. StartCoroutine(FallRaiseCoroutine(2.0f));
  58. }
  59. }