Add pingpong fade
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,12 @@ public class QuestManager : MonoBehaviour
|
||||
adventurer.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
GameManager.Instance.FadePingPong();
|
||||
}
|
||||
|
||||
public void RetryQuest()
|
||||
{
|
||||
GameManager.Instance.FadePingPong();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user