Game Clear Screen

How to Fade In Text

After defeating the boss we want to display the game clear text. Our boss music stops when the boss is defeated. After a few seconds when the game clear text is on screen the game cleared music starts.

BossHealth Script

In our script that handles our BossDeath we added some code. We grant some score for killing the boss. Then we instantiate the gamecleartext prefab and set the parent as canvas.

private void BossDeath()
{
_player.AddScore(100);
GameObject gameClearText = Instantiate(_gameClearText, _canvas.transform.position, Quaternion.identity);
gameClearText.transform.SetParent(_canvas.transform);

GameClearText Script

This script is on the prefab that gets instantiated when the boss is killed.
Using AudioSource.PlayDelayed we start the game clear music that is on the GameClearText gameobject.
The FadeIn() coroutine fades the game clear text in.

//handle
private AudioSource _audiosource;
private Text _text;

//config
private float _BGMduration = 5f;
private float _fadeDuration = 5f;

void Start()
{
_audiosource = GetComponent<AudioSource>();
_audiosource.PlayDelayed(_BGMduration);

_text = GetComponent<Text>();

StartCoroutine(FadeIn());
}

private IEnumerator FadeIn()
{
float currentTime = 0f;
while (currentTime < _fadeDuration)
{
float alpha = Mathf.Lerp(0f, 1f, currentTime/_fadeDuration);
_text.color = new Color(_text.color.r, _text.color.g, _text.color.b, alpha);
currentTime += Time.deltaTime;
yield return null;
}
yield break;
}

--

--

--

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

So, this is PentestSuite 3

Android 11 store file

Android continuous background services with NativeScript

How to set background image in Flutter?

Adding Comic Selection by Number

images/Networking/select.png

The Wrong, Hacked, and Correct way of Android Deep Linking for Redirected MultiSite with AutoVerify

Integrating HUAWEI Game Service Based on Cocos SDKHub — Initialization

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tristan Engel

Tristan Engel

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.

More from Medium

Ease of Building UI Elements in Unity — Part 3!

Advent of Cyber 3 Day 13 — They Lost The Plan! Walkthrough

My journey becoming a Unity game developer: Audio Manager: Play the audio clips with stable sound…

Using Courtroom Animation In A Breast Cancer Litigation