Platformer
//luckily cinemachine is so easy, you can use it with out code
This is a brief explanation of the work.
public void TakeDamage()
{
PlayerHealt--;//do damage
_particelSystemHeart.Play();
int i = PlayerHealt;//check for correct heart to remove
_material = _hearts[i].GetComponent-Image-().material;
StartCoroutine(PopDown());//start heart animation
if (CheckHealt())
StartCoroutine(Death());
}
public void TakeHealt()
{
int i = PlayerHealt;
PlayerHealt++;
_material = _hearts[i].GetComponent-Image-().material;
//check for correct heart to revive
StartCoroutine(PopUp());//start heart animation
}
private IEnumerator PopDown()
{
float elapsedTime = 0f;
while (elapsedTime < _dissolveTime)//while loop for the animation timer
{
elapsedTime += Time.deltaTime;
float lerpedDissolve = Mathf.Lerp(1.1f, 0f, (elapsedTime / _dissolveTime));
//lerp trough the dissolve
_material.SetFloat(_dissolveAmount, lerpedDissolve);
StartCoroutine(SetNullTimer());
//reset for _material to evade any none intentional animations
yield return null;
}
}
private IEnumerator PopUp()
{
float elapsedTime = 0f;
while (elapsedTime < _dissolveTime)
{
elapsedTime += Time.deltaTime;
float lerpedDissolve = Mathf.Lerp(0f, 1.1f, (elapsedTime / _dissolveTime));
_material.SetFloat(_dissolveAmount, lerpedDissolve);
StartCoroutine(SetNullTimer());
yield return null;
}
}