Ninja Cat Flyer - 2 of 6
-
Upload
shahed-chowdhuri -
Category
Technology
-
view
898 -
download
0
Transcript of Ninja Cat Flyer - 2 of 6
![Page 1: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/1.jpg)
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](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/2.jpg)
![Page 3: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/3.jpg)
Double-click Cat Controller in Scripts subfolder
![Page 4: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/4.jpg)
Type this inside the class before the Start() method
![Page 5: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/5.jpg)
Type these 3 lines
inside FixedUpdate()
just before it ends
![Page 6: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/6.jpg)
Run
Where
does the
cat go?
![Page 7: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/7.jpg)
![Page 8: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/8.jpg)
Right-click Scripts, click Create C# Script Name it “CameraFollow”
![Page 9: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/9.jpg)
Drag
Script to
Main Camera
Verify Script
Component
![Page 10: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/10.jpg)
Double-click CameraFollow in Scripts subfolder
![Page 11: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/11.jpg)
Type this inside the class before the Start() method
![Page 12: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/12.jpg)
Type these 4 lines inside the Update() method before the class ends
![Page 13: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/13.jpg)
Target Object: None
![Page 14: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/14.jpg)
Drag
Cat to
Camera’s
Target
Object
![Page 15: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/15.jpg)
Run
Does the
camera
follow
the cat?
![Page 16: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/16.jpg)
![Page 17: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/17.jpg)
Position:
• X = -3.5
• Y = 0
• Z = 0
![Page 18: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/18.jpg)
Type this inside the class before the Start() method
![Page 19: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/19.jpg)
Type this inside Start() method
![Page 20: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/20.jpg)
Add distanceToTarget to newCameraPosition
![Page 21: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/21.jpg)
Run
The cat
should
stay to
the left
![Page 22: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/22.jpg)
![Page 23: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/23.jpg)
Click “Game Object” Create Empty Verify Game Object in Hierarchy
![Page 24: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/24.jpg)
Rename to “mount1” Set Position: 0, 0, 0
![Page 25: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/25.jpg)
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](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/26.jpg)
In Project panel,
right-click
“Assets”
folder
Click Create, then Folder
Name it “Prefabs”
![Page 27: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/27.jpg)
Drag
“mount1”
into
“Prefabs”
NOTE: the “mount1” in the hierarchy should turn blue.
![Page 28: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/28.jpg)
![Page 29: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/29.jpg)
Right-click Scripts, click Create C# Script Name it “GeneratorScript”
![Page 30: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/30.jpg)
Drag
Script
to Cat
Verify Script
Component
![Page 31: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/31.jpg)
Double-click “GenerateScript” in Scripts subfolder
![Page 32: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/32.jpg)
Add “using” statement
above the class
Add 3 instance variables
inside the class
![Page 33: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/33.jpg)
Add 2 lines of code
inside the Start() method
![Page 34: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/34.jpg)
![Page 35: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/35.jpg)
Write AddMountains() method
with these 6 lines of code
![Page 36: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/36.jpg)
Create new method, add variables, initialize them
![Page 37: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/37.jpg)
Add foreach loop to figure out mountains
![Page 38: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/38.jpg)
Add foreach loop to destroy/add mountains
![Page 39: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/39.jpg)
Create FixedUpdate() Method, add 1 line of code
![Page 40: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/40.jpg)
![Page 41: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/41.jpg)
Select “Cat” in
Hierarchy
Drag “mount1”
to Current Mountains
Under GeneratorScript
![Page 42: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/42.jpg)
Select “Cat” in
Hierarchy
Drag “mount1”
PreFab
to Available Mountains
Under
GeneratorScript
![Page 43: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/43.jpg)
Do you have
extra mountains
in hierarchy?
(not part of
“mount1”)
Remove them!
![Page 44: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/44.jpg)
Run
The background
should scroll now!
![Page 45: Ninja Cat Flyer - 2 of 6](https://reader030.fdocuments.in/reader030/viewer/2022032422/55a903271a28ab457c8b47f0/html5/thumbnails/45.jpg)