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.

48 lines
1.3 KiB

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