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.

51 lines
1.4 KiB

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