Program a Basic Game
Learn more on Unity concept and important programming like:
• if-then statements,
• random value generation,
• arrays,
• collision detection,
• prefabs,
• instantiation
Basic Gameplay
• In game, should have kinds of :
• excitement,
• sense of urgency
• have “Real” objective
• In most interactive experience game, there are elements like :
• Non-Player enemies / Obstacles (part of the game, but not controlled by the player)
• Player have some abilities like attack/ defence
• Randomness (more exciting and some unpredictable element)
• Let’s program a simple game.
• A top-down game with the objective of throwing food to hungry animals - who are
stampeding towards a player - before they can run past the player.
• With the ability to launch projectiles and maneuver the player to keep the game alive.
Feed your animals
• Get the basic player movement working by
choosing which character you would like,
which types of animals you would like to
interact with, and which food you would like
to feed those animals.
Project Outcome:
• The player will be able to move left and right
on the screen based on the user’s left and
right key presses but will not be able to
leave the play area on either side.
[Link] a new Project
for Prototype 2
[Link] Unity Hub and create an empty
“Prototype 2” project in your directory.
[Link] to download the Prototype 2 Starter Files,
extract the compressed folder, and then import
the .unitypackage into your project.
[Link] the Project window, open the Prototype 2
scene and delete the SampleScene
[Link] the top-right of the Unity Editor, change your
Layout from Default to your custom layout
[Link] the Player, Animals,
and Food
1. Drag 1 Human, 3 Animals, and 1 Food object into the
Hierarchy.
2. Rename the character “Player”, then reposition the
animals and food so you can see them.
3. Adjust the XYZ scale of the food so it can easily see from
above.
[Link] the user’s horizontal input
1. In the Assets folder, create a “Scripts” folder, and a “PlayerController” script inside.
2. Attach the script to the Player and open it.
3. At the top of [Link], declare a new public float horizontalInput.
4. In Update(), set horizontalInput = [Link](“Horizontal”), then test to make sure it works in
the inspector
[Link] the player left-to-right
1. Declare a new public float speed = 10.0f;
2. In Update(), Translate the player side-to-side based on horizontalInput and speed
[Link] the player inbounds
1. In Update(), write an if-statement checking if the player’s left X position is less than a certain value
2. In the if-statement, set the player’s position to its current position, but with a fixed X location
[Link] up your code and
variables
1. Repeat this process for the right side of the screen.
2. Declare new xRange variable, then replace the hardcoded values
with them.
3. Add comments to the code
Next Lesson
• Create and throw endless amounts of food to feed our animals!