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