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.7 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CubeWithCrystals : ActiveBlock
  5. {
  6. public GameObject crystals;
  7. public override int GetInitative()
  8. {
  9. return 3;
  10. }
  11. public override IEnumerator OnRoundEnd(PlayerData[] allPlayers)
  12. {
  13. StartCoroutine(GrowCoroutine());
  14. yield return new WaitForSeconds(5);
  15. StartCoroutine(ShrinkCoroutine());
  16. isFinished = true;
  17. //yield break;
  18. }
  19. IEnumerator GrowCoroutine()
  20. {
  21. float elapsedTime = 0;
  22. Vector3 startPosition = crystals.transform.position;
  23. Vector3 endPosition = new Vector3(crystals.transform.position.x, crystals.transform.position.y + 1.0f, crystals.transform.position.z);
  24. float time = 0.8f;
  25. while (elapsedTime < time)
  26. {
  27. transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  28. yield return new WaitForEndOfFrame();
  29. elapsedTime += Time.deltaTime;
  30. }
  31. crystals.transform.position = endPosition;
  32. }
  33. IEnumerator ShrinkCoroutine()
  34. {
  35. float elapsedTime = 0;
  36. Vector3 startPosition = crystals.transform.position;
  37. Vector3 endPosition = new Vector3(crystals.transform.position.x, crystals.transform.position.y - 1.0f, crystals.transform.position.z);
  38. float time = 0.8f;
  39. while (elapsedTime < time)
  40. {
  41. transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  42. yield return new WaitForEndOfFrame();
  43. elapsedTime += Time.deltaTime;
  44. }
  45. crystals.transform.position = endPosition;
  46. }
  47. }