UNITY | PROJECT | SPACE SHOOTER 2D | 8. Lives UI, Play Button, & Game Manager

2
Importing UI Sprites
3
Adding UI Image
  • Adding UI Image for Score & Lives

 

4

  • Adding Sprite to UI Image as “Source Image”

 

5
UI Image Applied

 

6
UI Anchor

 

7.1
Adding & Configuring Sprite to UI Image for Scores UI
  • Adding Sprite to UI Image as “Source Image”

 

7.2
UI Anchor

 

8
Creating UI Text
  • Creating UI Text to count Player’s Life

 

9
Adding & Configuring UI Text to Image UI
  • In UI Text
    • set the default Text as “0”
    • change Font Style & Size
108-e1531887916889.png
UI Anchor

 

11
Creating UI Button
  • Create UI Button for Play Button

 

12

13

14
Adding Sprite to UI Button
  • In UI Button
    • Set the size
    • Add Sprites for “Target Graphic”(usual) & “Pressed Sprite”(pressed)

 

15
UI Anchor

 

16
Creating “GameManager” Script
17
Adding Reference
181.png
“GameManager” Script
  • To control PlayButton&Player with GameManager
    • create Public Object as a Reference
    • create an Enumeration, “GameManagerState” to tell Game State
      • Opening, GamePlay, and GameOver
    • create a Function, “UpdateGameManagerState()”
      • use “Switch Statement”
        • make 3 cases

 

19.1
“Play Button”
  • now, Play Button reacts to Clicking but nothing happens

 

19.2
“PlayerControl” Script
스크린샷 2018-07-18 오전 2.21.17
“Player”
20.1
“PlayerControl” Script
ec8aa4ed81aceba6b0ec83b7-2018-07-18-ec98a4eca084-1-22-31.png
“PlayerControl” Script
  • create “GameManager” GameObject as a reference
  • set “Player” inactive for the first moment of Game
  • In “Init()” method, which is called when Game Starts
    • set the current life(“lives”) as MaxLife
    • update UIText by using Text.text property
    • change the number(int “lives”) to string by using int.Tostring() method
    • set Player active when Game starts
  • In “OnTriggerEnter2D()” method(when a Collision with Player happens,)
    • the life is subtracted
    • when the life is 0,
      • use “SetManagerState” in “GameManager” Class with “GameOver”()*(putting the name of “enum”)
      • hide Player GameObject by set it “false”

 

8. Live UI, Play Button, - GameManager
“GameManager” Script
  • update “GameManager” Script
    • in “Start()” method
      • set “GMState” in “Opening”
    • in “UpdateGameManagerState()”
      • in case of “GamePlay”,
        • Set “PlayButton” active to hide it when Game Starts
        • Activate “Init()” method
    • Create” SetGameMangerState()” method to change the Game’s State, having “GameManagerState”(enum) as Parameter
    • in “StartGamePlay()” method
      • change “GMState” into “GamePlay”
      • Don’t forget to put “UpdateGameManagerState()”

 

 

21
“PlayButton” | Sprite & “On Click()”

 

  • In Play Button,
    • Add Sprite for “Target Graphics”(Usual) and “Pressed Sprite”(Pressed)
    • Add “On Click()” event and designate it “StartGamePlay()” method in “GameManager” Class
    • with this part, No Need to write to Star Game

 

231-e1531888420395.png
Adding Reference
ezgif.com-video-to-gif
“PlayButton” & “PlayerLife” working
26
“GameOver” Image added
  • Add “GameOver” Sprite
    • add the sprite to GameManager
    • add the Sprite to the scene
27
GameOver “Off”
  • Turn off “GameOver” for it to be hidden in the first moment of Game

 

28
“EnemySpawner” Script
  • Create a Function, “UnscheduleEnemySpawner()”, to stop the spawning when the game is over” by using “CancelInvoke()”

 

29
“GameManager” Script
  • Create “ChangeToOpeningState()” method
    • use “SetGameMangerState()” method
  • In Case of “GameOver”,
    • put “UnscheludeEnemySpawner()” method to stop the spanwing
  • In Case of “Opening”
    • turn off “GameOver” by using “GameObject.Setactive()”
30
Adding Reference
ezgif.com-video-to-gif
Game Working

 

UNITY TUTORIAL | PROJECT | Roll a Ball | 6. Collecting the Pick Up Object

Roll a Ball

Collecting the Pick Up Object

2
OnTriggerEnter() | CompareTag() | SetActive()
3
Add Tag
4
Add Tag
5
Add Tag
6
Apply Tag
7
Appy Tag
ezgif.com-video-to-gif.gif
SetActive not working
9
selcting
10
Unity’s Physics Engine | Static Collider | Dynamic Collider | Trigger | Trigger Collider
11
Collier | Trigger
12
Collier | Trigger

ezgif.com-video-to-gif (1)

13

14
RigidBody | Collider | Dynamic
15
Prefab | RigidBody | came to Dynamic
ezgif.com-video-to-gif (2)
RigidBody | Gravity
163.png
RigidBody | Gravity | Partial Solution
17
RigidBody | Gravity | Kinematic
ezgif.com-video-to-gif (3)
Gravity Overcome

 

18
Creating Variable as Reference
19
Creating UI Text

20

21
Chaing Position of UI
22
Configuring
23
NameSpace | UnityEngine.UI
24
Text.text | ToString
25
Custom Method to make the script shorter
26
Private Variable

 

ezgif.com-video-to-gif (1).gif
Text UI

 

27
Creating Win Text
28
changing​ the location of UI Text
29
Using Custom Method
30
Custom Variable
31
Private Variable
ezgif.com-video-to-gif (2)
UI Text