lucid-super-dream/Assets/Scripts/LoseLife.cs

47 lines
1.2 KiB
C#
Raw Normal View History

2021-01-05 13:10:20 +01:00
using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
2021-01-09 19:18:55 +01:00
using Ktyl.Util;
2021-01-05 13:10:20 +01:00
using UnityEngine;
using Weapons.Scripts;
public class LoseLife : MonoBehaviour
{
[SerializeField] private Renderer[] healthMarkers;
[SerializeField] private Renderer polygon;
2021-01-09 19:18:55 +01:00
[SerializeField] private CameraShake _cameraShake;
2021-01-05 13:10:20 +01:00
private EntityHealth _health;
private void Awake()
{
_health = GetComponent<EntityHealth>();
}
public void LifeLost(int livesLeft)
{
2021-01-09 19:45:52 +01:00
_cameraShake.Shake();
2021-01-09 17:18:29 +01:00
healthMarkers[livesLeft].transform.DOScale(Vector3.zero, 1f).SetEase(Ease.InBack).SetUpdate(true);
2021-01-05 13:10:20 +01:00
_health.enabled = false;
var timeVal = Time.timeScale;
Time.timeScale = 0;
WaitUtils.Wait(0.1f, false, () => Time.timeScale = timeVal);
var sequence = DOTween.Sequence();
for (int i = 0; i < 5; i++)
{
2021-01-09 17:18:29 +01:00
sequence.Append(polygon.material.DOFloat(1,"_FlashAmount", 0.2f).SetUpdate(true));
sequence.Append(polygon.material.DOFloat(0,"_FlashAmount", 0.2f).SetUpdate(true));
2021-01-05 13:10:20 +01:00
}
sequence.Play().OnComplete(() =>
{
_health.enabled = true;
});
}
}