Unity3D Tutorial – Simple 2D Platformer Prototyping (ISGM)

Continuing with our Implementing Simple Game Mechanics (ISGM) series, we’re making a tutorial to help you with setting up your 2D-Platformer prototype.

You can find our first two episodes of Implementing Simple Game Mechanics here:

Part One of this series can be found here: 
On The Road – Implementing Simple Game Mechanics

Part Two of this series can be found here: 
On the road: Implementing Simple Game Mechanics – 2D Platformer Part 2

Episode Information:

In this, we show you how to set up a simple Unity3D scene using a new empty 3D project.

After some introduction to the Unity editor, we show you how to detect keyboard input using C# and then hope that you take your newly learned skills to the next level by implementing more on your own.

What you should try to do on your own:

  • Implement movement functionality for the W, A, S, D keys by reusing the code presented in the tutorial video. You can write the basic input detection code and leave the code blocks empty as a placeholder for now if you don’t want the player object to do anything for that particular key press.
  • Try to implement a jump funcationlity by detecting the spacebar
  • Add in some platforms by creating new cube objects and placing them in thoughtful locations for prototype testing.

Tips:

The following if statement is core to detecting keyboard input:

// Placing this block of code in your update() loop will allow you to // detect keyboard input for the "A" key

if(Input.GetKeyDown(Keycode.A)){
    // Do something
}

Reference Documentation for GetKeyDown may be found here:
https://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html

If you want to jump ahead and play around with joystick input from something like an Xbox 360 controller would be to use:

// Placing this block of code in your update() loop will allow you to // detect joystick and or keyboard input on the horizontal axis based // on the properties mapped in the Unity Input settings found here
// Top Menus: Edit > Project Settings > Input

if(Input.GetAxis("Horizontal")){
    // Do something
}

Reference Documentation for GetAxis may be found here:
https://docs.unity3d.com/ScriptReference/Input.GetAxis.html