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