Sending a Message to the Player During Gameplay
Objective: Remind the player of their objective.
First we’ll create a Text object to hold the message. The alpha of the text will be 0 so it’s normally invisible. Then we’ll create an Animation Clip that will adjust the alpha to create the blinking and fade-out effect. In the Animator, we’ll create two states: a default with no animation clip, and another for the display clip we just created (ensuring the display clip doesn’t loop). We’ll use the ActivateText trigger to transition out of the default state into the display state.
We’ll set the Has Exit Time to true and the Exit Time to 1 so the clip will play once in its entirety then transition back to the default sate.
We’ll create a script using the singleton pattern (since we’ll only need one player messaging system in the game) so any other script can access it. When another scripts calls our DisplayMessage function, our script will set the text that was passed-in as the message and trigger the animation.
Now, in the win zone’s trigger collider (just in front of the exit doors), we’ll ask the Game Manager if our hero has the card. If he does, the win cutscene will activate. But if he doesn’t, we’ll call the UIText Instance’s DisplayMesssage method and tell it to display the message “You must have the key card.”
Now we have a way for any object in the scene to communicate with the player!