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.
 
 
 
 
 
 

65 lines
1.7 KiB

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 void OnWalkedOnByPlayer(PlayerData player)
{
base.OnWalkedOnByPlayer(player);
if (trappedCharacter == null)
{
player.character = trappedCharacter;
trappedCharacter.stuck = true;
trappedCharacter.StartAnimation(Character.Animation.Hit);
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;
}
}