Hello every one, today i'm gonna show you how to make GameController and UIController
First we need to create GameController script
Create some variables like score, game modes
Well as you can see everything is static so you can make the whole class static too
but in this case i want to create a GameController object with some buttons in inspector to do something
so i use MonoBehaviour
You need tags to be consistant, so define all tags here for later use
I realized this InitializeSelf() function is garbage
In Initialize(), tell the bird that Ground and Pipe are deadly
Hit play to test
and errors appear
So Ground and Pipe tag are not defined, you can define them manually but i'm not gonna do those silly actions
Let go back to GameController and create a function to define tags for you
First we need a button to trigger that function in inspector, remember tags can only be modified in Editor
Before adding any tag, you have to load the TagManager in ProjectSettings folder
Then clear all custom tags and apply that change
Next step is checking
if the tag you want to add does not match any default tag then add it to custom tag array
As you can see, the code is self explaining
And finally apply change to TagManager
This is default tags, no Ground or Pipe here
You can Add Tag but just hit refresh now
and every tag appear
Test again
the bird still alive because we didn't give Ground object Ground tag
and the bird normally die now
Back to GameController
Create a Setup() function that prepair everything before game Start
Remember to name everything as clear as you can, so you don't get confused later
Create some buttons to test
Setup then Start Game
the bird fall but no Game Over message appear
this is because the bird die Action not linked to GameOver, so let link them in Initialize() function
Well, in the last video i created an OnDead action in the bird
but it seem like it is private so let find and make it public
Now when the bird die GameOver will be fired
You can see the Game Over message is printed
GameController is almost done, let's go to next part UIController
Create a Canvas, you need a canvas to put UI elements into
If you are making a complex UI system, don't put everything in one Canvas
because when an element inside a Canvas changed, every other elements inside that Canvas will be updated too
In early stage of making game you should make sure every basic thing work nice before going to polish them
Create text with TextMeshPro for better quality
Let's create UIController and define all elements
Well, the bird alway fall and die at start, let's eliminate this problem
it easy just set the game to 2D mode when all Initialize functions happened
look, this is the start screen
Back to UIController, i'm gonna create some show functions to handle menus visibility
and some Editor buttons to test
You may wonder why i draw Inspector here, it because i want an easy way to access and test private member
and i don't have to swap between Editor script and Runtime script for a simple class like this
Look at what i am writing, it's pretty straightforward sentences
the meaning is when you hit a button, onClick() will be fired
and it will execute all listeners that have been added via AddListener() function
The last thing in this video is the touch input part
Create an image as target to receive touch events
make sure to enable Raycast target in image object
You can set alpha to 0 but this time i leave it some transparency for visibility
Turnoff all unnecessary Raycast targets for better performance
Unity will sent eventData through these Interfaces
for tap and simple swipe actions 3 pointer events is enough
Use upOrExited flag to make sure every Down action only result in one Swipe action
Add turn functions in 3D mode and remove them in 2D mode
Everything is in the description below, thank for watching and see you later
You can eliminate the UI freely without breaking the game logic
