using System.Collections; using System.Collections.Generic; using UnityEngine; public class Water : ActiveBlock { [SerializeField] [Tooltip("GameObject which appears when character respawns")] private GameObject lillyPad; [SerializeField] [Tooltip("Distance character will be submerged into the water")] private float FallDistance = 0.5f; private Character trappedCharacter; public override IEnumerator OnWalkedOnByPlayer(Character player, Vector3 moveDirection) { base.OnWalkedOnByPlayer(player, moveDirection); if (trappedCharacter == null) { player = trappedCharacter; trappedCharacter.stuck = true; trappedCharacter.StartAnimation(Character.Animation.Hit); yield return StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition + Vector3.down * FallDistance, 1)); } } public override void OnRoundEnd(PlayerData[] allPlayers) { base.OnRoundEnd(allPlayers); if (trappedCharacter != null) { StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition, 1)); StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition, 1)); trappedCharacter.stuck = false; } } private IEnumerator LerpToPosition(Transform target, Vector3 endPos, float time) { Vector3 _startPos = target.position; float elapsedTime = 0; while (elapsedTime / time < 1) { target.position = Vector3.Lerp(_startPos, endPos, (elapsedTime / time)); yield return new WaitForEndOfFrame(); elapsedTime += Time.deltaTime; } target.position = endPos; } }