UNITY | PROJECT | SPACE SHOOTER 2D | 11. Timer UI & GameTitle

2
Importing Timer UI

 

3
Adding Timer UI Image
  • Add an UI Image for Timer
    • Add Timer UI to “Source Image”
      • Press “Set Native Size”

 

4
Adding Timer Text
  • Add a UI Text for Timer Counter
    • Add Text for the default value
    • Change Font Style to “Bold”, Font Size to “30”
    • Add “Timer Controller” Script
    • Change Anchor to “Top-Right”

 

5
“TimerController” Script
  • Get the Reference for TimeUI
  • Claim “startTime”, “ellapsedTime” and “startCounter” as flag
  • Claim “minutes” and “seconds”
  • In “Start()” method
    • Set the flag to false
    • Get the Component of “Text”
  • Create a Function, “StartTimeCounter()” to start the Timer
    • Get the current time when the timer is started
    • Set the Flag to True
  • Create a Function, “StopTimeCounter()” to stop the Timer
    • Set the Flag to False
  • In “Update()” method,
    • if the flag is True (when it is on)
      • Get the Elapsed Time by subtracting “startTime” from the Current Time in this very frame
      • Get the minute and second based on the Elapsed Time
      • Update the Timer UI by accessing the Text Property with String.Format
6.1
“GameManager” Script
  • Add codes to Start and Stop the Timer
    • Get the Component of “TimerCounter” Class to use “StartTimeCounter()” and “StopTimeCounter()”
6.2
“Timer” Working

 

7.1
Importing “GameTitle”
  • Add “Game Title” image on the Hierarchy
    • Set the sorting layer to “Effect”

 

8
“GameManager” Script
  • Add Codes to Turn on & off Game Title by using “GameObject.SetActive()”
    • When Case “Opening”,
      • Set Game Title On
    • When Case “GamePlay”
      • Set Game Title Off
7.2
“GameTitle” Working

UNITY | PROJECT | SPACE SHOOTER 2D | 9. Score UI, SFX & BGM

2
Resetting Position when Game Starts
3
Score Text UI
4
Creating “GameScore” Script
5
“GameScore” Scrip
  • Set a Property, “Score”
  • In “Start()” method,
    • Get “Text” component to “scoreTextUI”
  • Create “UpdateScoreTextUI()”
    • create “scoreStr” string variable like a temporary bowl to keep “score”
    • put “scoreStr” into “scoreTextUI” by using “Text.text”
9. Score UI, SFX - BGM
Tagging & Adding Script

 

7
Getting “ScoreTextUI” with Tag
9. Score UI, SFX - BGM
“scoreTextUI” Reference | Set the score to 0 when Game Starts
  • Add scoreTextUI
  • in case of “GamePlay”
    • set the score to 0 by setting the Property of “GameScore” class
8
Don’t Forget to Add Reference
10
Adding “AudioSource” & BGM
  • Create “BackGroundMusic” GameObject from EmptyGameObject
  • Add “Audio Source” to “BackGroundMusic”
    • Add “BackGroundMusic”  to “Audio Source”
11
Adding “AudioSource” & BGM
  • Add “Audio Source” to “Player”
    • Add “Laser” sound to “Audio Source”
12
“PlayerControl” Script
  • Add “audioSource” variable of “AudioSource” Class to use Audio Source attached to GameObject this script is attached to
  • In “Start()” method,
    • Get “Audiosource” component to “audioSource”
  • In “Update()”
    • add “audioSource.Play()” to play the laser sound when Space Bar is pressed

 

 

13
Adding “AudioSource” & BGM
  • Add “Audio Source” to “Explosion” Prefab
    • Add “Explosion” sound to “Audio Source”
  • For Prefab,
    • No need to create or configure a script
    • when Prefab appears in the scene, “Audio Source” is activated with “Play On Wake” on

 

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |14. Counting Points and Score

2
Creating Canvas & UI Text
3
Changing “Anchor” of UI Text
4
Changing “Anchor” to “Top-Left”
11
adding codes to “Game Controller” script
12
adding Text UI to “Game Controller” script as a reference
13
Adding Codes to “DestroyByContact” script | making a reference of “Game Controller” to use “AddScore” Function
14
setting Score Value in Asteroid Prefab
5
Creating “Game Score” Script

ezgif.com-video-to-gif-2

Another way of setting Score UI

6
Game Score Script
7
Adding “Game Score” script to Text UI
8
Tagging UI
9
adding codes to increment score after destroying a hazard