TP 2 Gaming
TP 2 Gaming
TP 2: 2D game
Create a new unity project and name it Flappy.
Create new folders Sprites, Animations, Scripts, Scenes and so on under the project.
Download flappy bird pictures.
Transform them to sprites. We need here a background, a bird, a pipe. Then use them.
We firstly add a background to the scene. Use 9:16 aspect to fit the camera.
(If you don’t have this aspect, choose Aspect Rate (9:16 for width and height)).
1
Aroua Taamallah Mobile Game Programming 2LSI
Add a box collider 2d to the ground and set to auto tiling to match the size.
Add pipes and create an empty game object place it at the center of the 2 pipes, name it Pipe
then add them as children of that object.
Create a new script for the pipe to move to the left and name it Move.
2
Aroua Taamallah Mobile Game Programming 2LSI
Create an empty game object and name it PipeSpawner, set its position in the position of the
pipe and add new script PipeSpawner.
Useful Links
The Function GetMouseButtonDown()
https://docs.unity3d.com/ScriptReference/Input.GetMouseButtonDown.html
Velocity : rate of change of rigidbody position
https://docs.unity3d.com/2017.4/Documentation/ScriptReference/Rigidbody-velocity.html
3
Aroua Taamallah Mobile Game Programming 2LSI
Tp 2 Part 2
We will now make an action when the player loose.
Create UI canvas, name it GameOverCanvas.
Then UI Image, add this button to the source button.
Add an empty GameObject and add the GameManager Script to this object
Add GameManager and a function that activates the canvas when the collision is detected
between the bird and the pipes.
Return to the FlyBird script and add a reference to the GameManager
4
Aroua Taamallah Mobile Game Programming 2LSI
Go to the GameManager Script and add replay function to reload the scene.
Add this library first then
Replay function
Add a button to the image then add the function Replay to the button to load the
scene.
5
Aroua Taamallah Mobile Game Programming 2LSI
Add the pipe prefab to the scene add an empty game object as a child of the pipe and add a
Box Collider 2D to it; edit the collider to fit the space between the pipes and check is trigger.
Add a new script AddScore
Delete the existing pipe prefab and replace it with the new one and drag and drop it in the
pipeSpawner.
6
Aroua Taamallah Mobile Game Programming 2LSI
Tp 2 Part 3
Main menu creation
Create a new scene, name it Start Menu.
Create a canvas, a panel rename it to Background and add to it a background image.
Create a UI text, set text to “Play”, Font Style to Bold and Font Size to 30. Center it.
Create a UI button, rename it “Play button”, move it up and set the color of the image to
black, and disable the image.
Delete the text of the button and replace it with the play text.
Enable the image and decrease the black color as follows.
Duplicate the button and name it “Quit button”, set the text to “Quit”.
Create an empty game object and name it “main menu”. Add the 2 buttons as children of this
object.
Create a new script name it “main menu”
7
Aroua Taamallah Mobile Game Programming 2LSI