Skip to Main Content






Unity tutorial

Scene

Go to Unity Hub

Create a new 3D project


Click on File > Save as > save it in the Scenes folder > name it "Game"

Delete the "SampleScene" from the folder

Ball and Platform

Right-click in the hierarchy window > 3D object > Cube, name it "Platform", in the inspector window:

  • Click Add Component > Rigidbody
  • In the Rigidbody component:
    • Change "Mass" to 10000 (Changing the mass of the platform to 10000 will make the platform unaffected by the momentum of the ball.)
    • Change Angular Drag to 0
    • Uncheck "Use Gravity"
    • Change "Collison Detection" to Continuous
    • Under Constraints; check Freeze Position Y and Z
    • Under Constraints; check Freeze Rotation X, Y, and Z (to stop the ball from rolling)

 

 

In the Project window, right click on Assets> Create > Folder, name it "Material"

In the Material folder, right-click > Create > Material, name it "Dirt" > in the Inspector window:

  • In color container, change it to brown

Drag the Dirt material onto the Platform gameobject

 

Right click on Platform > 3D object > Cube // need some description of child: term are important to learn

Right-click on the Cube > Rename > name it "Grass"

Click on the Grass > in the inspector window:

  • Remove the "Box Collider" component by clicking on the 3 dots > Remove Component
  • Change Position Y to 0.5
  • Change Scale X to 1.01, Scale Y to 0.05, Scale Z to 1.01 (increasing the X and Z scale by 0.01 will help the engine to render grass over dirt)

Right-click again in the material folder > Create > Material

Name the material "Grass" > in the color container, change it to green

Drag the Grass material onto the Grass gameobject

 

Click on Assets in Project window > right-click > Create > Folder, name it "Prefabs" (Prefab stands for prefabricated building and it is useful for replicating a GameObject with similar component content)

Drag the platform to the folder

 

Click on Assets in Project window > right-click > Create > Folder, name it "Physics Material"

Right-click inside the folder > Create > Physics Material

Name it "NoFriction". In the inspector window:

  • Change Dynamic and Static Friction to 0
  • Change Friction Combine and Bounce Combine to Minimum

(physics material "NoFriction" is added to that platform prefab so that the ball can move on the platform without any friction)

Select the Platform prefab in the Prefab folder. In the inspector window:

  • From the Physics Material folder just created, drag "NoFriction" to the Physics Material placeholder under Box Collider.

 

Right-click on the hierarchy window > 3D object > Sphere, name it "Ball", in the inspector window:

  • Change Position X to 0, Position Y to 6, Position Z to 0
  • Change Scale X to 0.5, Scale Y to 0.5, Scale Z to 0.5
  • Add a Rigidbody component
    • Change Drag to 2 (slow the fall of the ball)
    • Change Angular Drag to 0
    • Make sure Use Gravity is checked
    • Check Freeze Rotation X, Y, and Z (stop the ball from rolling)

 

In the material folder, right-click > Create > Material, name it "Gold", in the Inspector window:

  • Change the color to gold
  • Change the smoothness to 1

Drag the Gold material to the Ball gameobject

Drag the Ball to the Prefab folder

 

Click File > Save

Setting up scene

Right-click on the Hierarchy window > Create Empty, name it "Level", in the Inspector window:

  • Change its Position X, Position Y, and Position Z to 0

Do this until it there are 3 GameObjects underneath the Level

  • Rename the first Gameobject "Level 1", in the Inspector window:
    • Change its Position Y to -2
  • Rename the second Gameobject "Level 2", in the Inspector window:
    • Change its Position Y to -0.5
  • Rename the third Gameobject "Level 3", in the Inspector window:
    • Change its Position Y to 1

 

Delete the Platform in the Hierarchy window

Drag the Platform from the prefab folder into Level 1, Level 2, and Level 3 

Turn the perspective to face the scene by right-clicking on the axis > Back > zoom and pan to fit 

(this will give a good perspective when building the level)

 

Duplicate the Platform in "Level 1" 5 times, (Shortcut for duplicate CTRL+D)

Change the Position X of the platforms as such:

  • Platform: 0
  • Platform(1): 1
  • Platform(2): 2
  • Platform(3): 10
  • Platform(4): 18
  • Platform(5):  19

Duplicate the Platform in "Level 2" 5 times, (Shortcut for duplicate CTRL+D)

Change the Position X of the platforms as such:

  • Platform: 4
  • Platform(1): 8
  • Platform(2): 13
  • Platform(3): 14
  • Platform(4): 21
  • Platform(5):  22

Duplicate the Platform in "Level 3" 1 time, (Shortcut for duplicate CTRL+D)

Change the Position X of the platforms as such:

  • Platform: 6
  • Platform(1): 16

 

Right-click the Hierarchy window > Create Empty

Rename it SpawnPoint (This will be the spawn point for the "Ball" when it falls)

Click on it, in the inspector window:

  • Change the Position X to 0, Position Y to 12, Position Z to 0.

 

Right-click the Ball > Create Empty, name it "GroundCheck" (This will be to check if there is contact between the "Ball" or the "Platform"), in the inspector window:

  • Change the Position X to 0, Position Y to -0.5, Position Z to 0.
  • Change the Scale X to 2, Scale Y to 2, Scale Z to 2.

Background

Click on the Asset Store tab

 

Search for "MK - Space Background"

Click on it > click Download > click Import

 

After importing it should appear in the Assets folder

Click back to the Scene tab

 

In the Hierarchy window, right-click on the main camera > Create Empty, name it "Background", in the inspector window:

  • Click on Add Component > Sprite Renderer
    • From the "Space Background > Sprites > Background" folder, drag "Space Background  3" to the Sprite placeholder
  • Change the Position Y to -5, Position Z to 11
  • Change the Scale X to 1.3, Scale Y to 1.2

(In the Game tab, the background might seem to not fit the entire screen as shown in the video, that is due to a different resolution screen, the final build of the game is going to be the same)