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 bool isLillyPadUp = false;
|
|
|
|
private Character trappedCharacter;
|
|
|
|
public override int GetInitative()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
public override IEnumerator OnWalkedOnByPlayer(Character player, Vector3 moveDirection)
|
|
{
|
|
yield return StartCoroutine(base.OnWalkedOnByPlayer(player, moveDirection));
|
|
|
|
if (trappedCharacter == null)
|
|
{
|
|
CurrentPlayer = null;
|
|
trappedCharacter = player;
|
|
trappedCharacter.stuck = true;
|
|
|
|
trappedCharacter.StartAnimation(Character.Animation.Hit);
|
|
yield return StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition + Vector3.down * FallDistance, 1));
|
|
}
|
|
|
|
}
|
|
|
|
public override void OnLeftByPlayer(Character player)
|
|
{
|
|
base.OnLeftByPlayer(player);
|
|
if (isLillyPadUp)
|
|
{
|
|
StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition + Vector3.down * FallDistance, 1));
|
|
isLillyPadUp = false;
|
|
}
|
|
|
|
}
|
|
|
|
public override IEnumerator OnRoundEnd(PlayerData[] allPlayers)
|
|
{
|
|
Debug.Log("reseting water");
|
|
|
|
if (trappedCharacter != null)
|
|
{
|
|
StartCoroutine(LerpToPosition(trappedCharacter.transform, VisualPosition, 1));
|
|
yield return StartCoroutine(LerpToPosition(lillyPad.transform, VisualPosition, 1));
|
|
trappedCharacter.stuck = false;
|
|
isLillyPadUp = true;
|
|
trappedCharacter = null;
|
|
|
|
}
|
|
isFinished = true;
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
}
|