ninja cat flyer - 2 of 6

45
Derived from Kirill Muzykov’s Rocket Mouse Tutorial http:// www.raywenderlich.com/69392/make-game-like-jetpack-joyride-unity-2d-part-1 @shahedC WakeUpAndCode.com

Upload: shahed-chowdhuri

Post on 17-Jul-2015

897 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Ninja Cat Flyer - 2 of 6

Derived from Kirill Muzykov’s Rocket Mouse Tutorial

http://www.raywenderlich.com/69392/make-game-like-jetpack-joyride-unity-2d-part-1

@shahedC

WakeUpAndCode.com

Page 2: Ninja Cat Flyer - 2 of 6
Page 3: Ninja Cat Flyer - 2 of 6

Double-click Cat Controller in Scripts subfolder

Page 4: Ninja Cat Flyer - 2 of 6

Type this inside the class before the Start() method

Page 5: Ninja Cat Flyer - 2 of 6

Type these 3 lines

inside FixedUpdate()

just before it ends

Page 6: Ninja Cat Flyer - 2 of 6

Run

Where

does the

cat go?

Page 7: Ninja Cat Flyer - 2 of 6
Page 8: Ninja Cat Flyer - 2 of 6

Right-click Scripts, click Create C# Script Name it “CameraFollow”

Page 9: Ninja Cat Flyer - 2 of 6

Drag

Script to

Main Camera

Verify Script

Component

Page 10: Ninja Cat Flyer - 2 of 6

Double-click CameraFollow in Scripts subfolder

Page 11: Ninja Cat Flyer - 2 of 6

Type this inside the class before the Start() method

Page 12: Ninja Cat Flyer - 2 of 6

Type these 4 lines inside the Update() method before the class ends

Page 13: Ninja Cat Flyer - 2 of 6

Target Object: None

Page 14: Ninja Cat Flyer - 2 of 6

Drag

Cat to

Camera’s

Target

Object

Page 15: Ninja Cat Flyer - 2 of 6

Run

Does the

camera

follow

the cat?

Page 16: Ninja Cat Flyer - 2 of 6
Page 17: Ninja Cat Flyer - 2 of 6

Position:

• X = -3.5

• Y = 0

• Z = 0

Page 18: Ninja Cat Flyer - 2 of 6

Type this inside the class before the Start() method

Page 19: Ninja Cat Flyer - 2 of 6

Type this inside Start() method

Page 20: Ninja Cat Flyer - 2 of 6

Add distanceToTarget to newCameraPosition

Page 21: Ninja Cat Flyer - 2 of 6

Run

The cat

should

stay to

the left

Page 22: Ninja Cat Flyer - 2 of 6
Page 23: Ninja Cat Flyer - 2 of 6

Click “Game Object” Create Empty Verify Game Object in Hierarchy

Page 24: Ninja Cat Flyer - 2 of 6

Rename to “mount1” Set Position: 0, 0, 0

Page 25: Ninja Cat Flyer - 2 of 6

Drag

“mountains”,

“floor” and

“ceiling” into

“mount1”

NOTE: you can also add other objects that you may have added as part of the background.

Page 26: Ninja Cat Flyer - 2 of 6

In Project panel,

right-click

“Assets”

folder

Click Create, then Folder

Name it “Prefabs”

Page 27: Ninja Cat Flyer - 2 of 6

Drag

“mount1”

into

“Prefabs”

NOTE: the “mount1” in the hierarchy should turn blue.

Page 28: Ninja Cat Flyer - 2 of 6
Page 29: Ninja Cat Flyer - 2 of 6

Right-click Scripts, click Create C# Script Name it “GeneratorScript”

Page 30: Ninja Cat Flyer - 2 of 6

Drag

Script

to Cat

Verify Script

Component

Page 31: Ninja Cat Flyer - 2 of 6

Double-click “GenerateScript” in Scripts subfolder

Page 32: Ninja Cat Flyer - 2 of 6

Add “using” statement

above the class

Add 3 instance variables

inside the class

Page 33: Ninja Cat Flyer - 2 of 6

Add 2 lines of code

inside the Start() method

Page 34: Ninja Cat Flyer - 2 of 6
Page 35: Ninja Cat Flyer - 2 of 6

Write AddMountains() method

with these 6 lines of code

Page 36: Ninja Cat Flyer - 2 of 6

Create new method, add variables, initialize them

Page 37: Ninja Cat Flyer - 2 of 6

Add foreach loop to figure out mountains

Page 38: Ninja Cat Flyer - 2 of 6

Add foreach loop to destroy/add mountains

Page 39: Ninja Cat Flyer - 2 of 6

Create FixedUpdate() Method, add 1 line of code

Page 40: Ninja Cat Flyer - 2 of 6
Page 41: Ninja Cat Flyer - 2 of 6

Select “Cat” in

Hierarchy

Drag “mount1”

to Current Mountains

Under GeneratorScript

Page 42: Ninja Cat Flyer - 2 of 6

Select “Cat” in

Hierarchy

Drag “mount1”

PreFab

to Available Mountains

Under

GeneratorScript

Page 43: Ninja Cat Flyer - 2 of 6

Do you have

extra mountains

in hierarchy?

(not part of

“mount1”)

Remove them!

Page 44: Ninja Cat Flyer - 2 of 6

Run

The background

should scroll now!

Page 45: Ninja Cat Flyer - 2 of 6