Skip to content

Commit

Permalink
Add countdown and animation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvriel committed Dec 19, 2024
1 parent 7dbbc79 commit 5d6f9b5
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Assets/Scenes/Main.unity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions Assets/StartScreen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using DG.Tweening;
using UnityEngine;
using UnityEngine.Events;

namespace Netherlands3D.Twin
{
public class StartScreen : MonoBehaviour
{
public UnityEvent getReady = new();
public UnityEvent startGame = new ();
[SerializeField] private CanvasGroup canvasGroup;
[SerializeField] private CanvasGroup CountdownOne;
[SerializeField] private CanvasGroup CountdownTwo;
[SerializeField] private CanvasGroup CountdownThree;
[SerializeField] private float fadeDuration = .3f;
[SerializeField] private float countDownDuration = 1f;
[SerializeField] private float countDownTargetScale = .5f;

private void Start()
{
Show();
}

private void OnEnable()
{
CountdownThree.alpha = 1f;
CountdownThree.gameObject.SetActive(false);
CountdownTwo.alpha = 1f;
CountdownTwo.gameObject.SetActive(false);
CountdownOne.alpha = 1f;
CountdownOne.gameObject.SetActive(false);
}

public void Show()
{
gameObject.SetActive(true);
}

public void StartGame()
{
var sequence = DOTween.Sequence(this);
sequence.Append(canvasGroup.DOFade(0, fadeDuration).OnComplete(TriggerGetReady));
sequence.AppendCallback(() => CountdownThree.gameObject.SetActive(true));
sequence.Append(CountdownThree.transform.DOScale(countDownTargetScale, countDownDuration));
sequence.Join(CountdownThree.DOFade(0, countDownDuration).SetEase(Ease.InQuad));
sequence.AppendCallback(() => CountdownThree.gameObject.SetActive(false));
sequence.AppendCallback(() => CountdownTwo.gameObject.SetActive(true));
sequence.Append(CountdownTwo.transform.DOScale(countDownTargetScale, countDownDuration));
sequence.Join(CountdownTwo.DOFade(0, countDownDuration).SetEase(Ease.InQuad));
sequence.AppendCallback(() => CountdownTwo.gameObject.SetActive(false));
sequence.AppendCallback(() => CountdownOne.gameObject.SetActive(true));
sequence.Append(CountdownOne.transform.DOScale(countDownTargetScale, countDownDuration));
sequence.Join(CountdownOne.DOFade(0, countDownDuration).SetEase(Ease.InQuad));
sequence.AppendCallback(() => CountdownOne.gameObject.SetActive(false));
sequence.AppendCallback(TriggerStartOfGame);
sequence.Play();
}

private void TriggerGetReady()
{
gameObject.SetActive(false);
getReady.Invoke();
}

private void TriggerStartOfGame()
{
startGame.Invoke();
}
}
}
11 changes: 11 additions & 0 deletions Assets/StartScreen.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d6f9b5

Please sign in to comment.