2019-06-01 net

(Brent) #1

PROJECTS
Unity


GET INSPIRED


PROJECTS

Cuphead by StudioMDHR
http://www.cupheadgame.com/
Cuphead, by StudioMDHR, is a 2D indie game based on the
style of classic 1930s cartoons. It combines watercolour-style
backgrounds, hand-drawn animations, complex action and
interactions, as well as an original soundtrack.

Unruly Heroes by Magic Design Studios
https://www.unrulyheroes.com
Unruly Heroes is an action-adventure game inspired by the famous
Chinese novel, A Journey to the West, better known as the Monkey
King Legend. This is another incredible example of 2D side-
scrolling adventure gaming.

Ori and the Blind Forest by Moon Studios
https://www.orithegame.com/
A beautiful example of the capabilities of the Unity platform,
when combined with amazing artists and storytelling. Ori is a 2D
platform game with incredible visuals.

First, we get a reference to the RigidBody2D
component we added to the plane. Then we store the
current velocity of the plane in the vertical direction
(y) and store it in a variable called ‘rot’. Then we use
Unity’s quaternion Euler method to set a rotation
target for the object. We use our ‘rot’ value to set
the final value, which is rotation around the z axis.
That’s the one pointing straight towards the camera.
Then we set the actual rotation of the current object
to a value somewhere between our target rotation
and current rotation, depending on the amount of
time passed since our last update. Basically this is
‘tweening’ or ‘lerpping’ between the current rotation
and the target, for a smoother rotation.
Save the code and test it. You should see the plane
angle downwards as it falls. Later we’ll add collision
detection to this object, so we can react to events
such as hitting obstacles or triggers to score points.

STEP 13: ADD GAME CONTROL
There are many ways to structure your Unity code. I
like to create an empty game object in the scene and
attach a main script to it. This will run in the root of
the scene and can serve as a main game controller.
Add the empty object to the scene and add a script
component to it via the Inspector and call it ‘main’.
Open up your new main script and add the
following code after the public class declaration,
before the update function:

public GameObject plane;
public float strength = 10.0f;
private bool dead = false;

Save the script and return to Unity. Drag and drop
your ‘plane’ game object to the new empty slot in
your script component in the Inspector for the ‘main’
game object. Once you have the plane linked to your
main script, return to the Visual Studio editor.
Next we want to listen for the user pressing the
space bar. You could set up other keys or buttons if
you wish, Unity supports them all. But for now let’s
use the space bar. Update your update function in
your main script to look like the following code:

void Update() {
if (Input.GetKeyDown(KeyCode.Space) && !dead)
{
Debug.Log(“Space key was pressed.”);
Rigidbody2D rb = plane.
GetComponent<Rigidbody2D>();
rb.velocity = Vector2.zero;
rb.AddForce(transform.up * strength);
}
}
Free download pdf