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.

87 lines
2.3 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Water : ActiveBlock
  5. {
  6. [SerializeField]
  7. [Tooltip("GameObject which appears when character respawns")]
  8. private GameObject lillyPad;
  9. [SerializeField]
  10. [Tooltip("Distance character will be submerged into the water")]
  11. private float FallDistance = 0.5f;
  12. private bool isLillyPadUp = false;
  13. private Character trappedCharacter;
  14. public override int GetInitative()
  15. {
  16. return 0;
  17. }
  18. public override IEnumerator OnWalkedOnByPlayer(Character player, Vector3 moveDirection)
  19. {
  20. yield return StartCoroutine(base.OnWalkedOnByPlayer(player, moveDirection));
  21. if (trappedCharacter == null)
  22. {
  23. CurrentPlayer = null;
  24. trappedCharacter = player;
  25. trappedCharacter.stuck = true;
  26. trappedCharacter.StartAnimation(Character.Animation.Hit);
  27. yield return StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition + Vector3.down * FallDistance, 1));
  28. }
  29. }
  30. public override void OnLeftByPlayer(Character player)
  31. {
  32. base.OnLeftByPlayer(player);
  33. if (isLillyPadUp)
  34. {
  35. StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition + Vector3.down * FallDistance, 1));
  36. isLillyPadUp = false;
  37. }
  38. }
  39. public override IEnumerator OnRoundEnd(PlayerData[] allPlayers)
  40. {
  41. Debug.Log("reseting water");
  42. if (trappedCharacter != null)
  43. {
  44. StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition, 1));
  45. yield return StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition, 1));
  46. trappedCharacter.stuck = false;
  47. isLillyPadUp = true;
  48. trappedCharacter = null;
  49. }
  50. isFinished = true;
  51. }
  52. private IEnumerator LerpToPosition(Transform target, Vector3 endPos, float time)
  53. {
  54. Vector3 _startPos = target.position;
  55. float elapsedTime = 0;
  56. while (elapsedTime / time < 1)
  57. {
  58. target.position = Vector3.Lerp(_startPos, endPos, (elapsedTime / time));
  59. yield return new WaitForEndOfFrame();
  60. elapsedTime += Time.deltaTime;
  61. }
  62. target.position = endPos;
  63. }
  64. }