0% found this document useful (0 votes)
35 views

TP 2 Gaming

Uploaded by

Adem Massous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

TP 2 Gaming

Uploaded by

Adem Massous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Aroua Taamallah Mobile Game Programming 2LSI

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)).

Figure 1 Adding aspect 9 :16


Creation of the bird and its animation.
Add the ground. Set the bird and the ground layers to 1 and 2 respectively.
Add physics and capsule collider to the bird and set its direction to horizontal and edit it to fit
the bird.
Add a script that sets the velocity to up and multiply it by 1 if GetMouseButtonDown(0). Set
the gravity Scale (of Rigidbody 2D) and the velocity 1.4 and hit play.

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.

Add box collider 2D to the pipes and let it fit them.


Set the speed to 1.4
Add pipe to prefabs

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.

And hit play.

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.

Create a new Image, add this button to the source button.

Create a new Image, add this button to the source button.

Add an empty GameObject and add the GameManager Script to this object

Add the canvas to the GameManager

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

And in Unity add the Game Manager

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.

Deactivate the GameOverCanvas then create a new ScoreCanvas


Create a UI text, place it on top of the screen then increase the font size to 70

5
Aroua Taamallah Mobile Game Programming 2LSI

Align the paragraph to the center.


Set the text to 0
Add a script Score to the text

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”

Add the scenes to the build settings.

7
Aroua Taamallah Mobile Game Programming 2LSI

Add StartGame() function to the play button

and QuitGame() function to the quit button as follows:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy