Let's Make A Super Simple Unity Game! Part 1: Movement
Posted on February 7th, 2018
Before you start, download Unity here: https://unity3d.com/get-unity/download
Let's start with the basics --
Take a look at the Hierarchy, Scene Window, Inspector, and Assets pane. What do each of them do?
Look at how to manipulate the Scene Window -- zoom in, out, pan.
Look at how to make new objects by right-clicking in the Assets or Hierarchy pane (and what the difference is)
Look at how to select objects and change their properties either using W, E, R or changing values in the Inspector window
What are the default things that come with the scene? (look in hierarchy). What do they do?
Let's make a player character --
Create a new plane scaled up on the Y axis.
Create a new cube, position it above the plane. Add a rigidbody component. (What does this do?)
Position the camera where you want it to be default, then make it a child of the cube
Make a new material, add it to the floor (or player)
Let's let the player move forward, back, and jump up.
Use this script: https://gist.github.com/dacharya64/119a775dc10d9f13919d1d7e37ec8282
Fix the code!
Show how to modify public values in Inspector
Let's make some obstacles --
Make a new wall (whatever primitive you want)
Showing how to create a new prefab 'wall'
Make some copies of wall prefab
Apply a material to one instance of the prefab, then apply across all prefabs
Download the Unity project here: https://github.com/dacharya64/SampleGame
What's next? Some possibilities:
-Creating a GUI and menus
-Creating collectibles and transitioning between scenes
-Creating and adding materials / textures
-Importing your own 3D assets
-More code (movement, collision, etc)
-More game genres (shooter, open world, etc)
And more...!
//Code
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerMovement : MonoBehaviour { | |
public float speed; //how fast the player moves | |
public float jumpForce; //how high the player jumps | |
//Private Vars | |
private Rigidbody rb; | |
// Use this for initialization | |
void Start () { | |
//get the rigidbody compoment of what this is attached to (ex. the player) | |
rb = GetComponent | |
} | |
// Update is called once per frame | |
void Update () { | |
if (Input.GetKeyDown(KeyCode.W)) { //JUMP | |
rb.velocity = transform.up * jumpForce; | |
} | |
if (Input.GetKey(KeyCode.A)) { //MOVE LEFT | |
transform.position += Vector3.left * speed * Time.deltaTime; | |
} | |
if (Input.GetKey(KeyCode.D)) { //MOVE RIGHT | |
// **How do you rewrite the 'move left' code for moving right?** | |
// Answer below | |
} | |
} | |
} | |
/* | |
* | |
* | |
* | |
* | |
* | |
* | |
* SOLUTION: transform.position += Vector3.right * speed * Time.deltaTime; | |
*/ |