Add pingpong fade

This commit is contained in:
2023-07-09 10:25:40 +02:00
parent a9fbeef0b4
commit 576a873a02
3 changed files with 400 additions and 3 deletions

View File

@@ -1,12 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public Image fadeRect;
public DialogueController dialogueController;
[SerializeField] private float m_fadeT;
private float m_fadeTotal;
[SerializeField] private bool m_showFade = false;
[SerializeField] private float m_fadeDuration = 1;
private void Awake()
{
if (Instance == null)
@@ -19,5 +26,38 @@ public class GameManager : MonoBehaviour
}
}
private void Update()
{
//Fade image towrads target
if(m_showFade)
{
if (m_fadeTotal < m_fadeDuration / 2)
{
m_fadeT += Time.deltaTime;
} else
{
m_fadeT -= Time.deltaTime;
}
m_fadeTotal += Time.deltaTime;
if(m_fadeT < 0)
{
m_showFade = false;
m_fadeT = 0;
m_fadeTotal = 0;
}
fadeRect.color = new Color(0f, 0f, 0f, Mathf.Lerp(0, 1, m_fadeT));
}
}
public void FadePingPong()
{
m_fadeTotal = 0;
m_showFade = true;
}
}