?
Providing?2D?Gameplay?with?Unity?2
Author:?Graveck?Interactive
Last?Revision:?19-FEB-2008
Contents
1.Introduction
Why?2D?is?the?Bee's?Knees?4 Prerequisites?6 2.Setting?The?Scene
Getting?in?the?2D?Mind-Set?7 A?Closer?Look?9 Setting?the?Level?Attributes?10 Object?Profile:?Level?Attributes?12 Object?Profile:?Death?Zone?13 Setting?Up?the?Platforms?13 Object?Profile:?Platform?(Prefabs)?15 Object?Profile: Pre-Assembled?Platform?16 Introducing?Lerpz,?Our?Lovely?Character?17 Placing?Lerpz?18 Directing?the?Camera?19 Object?Profile:?Character?(Lerpz)?20 Lighting?our?Scene?22 Spicing?up?the?Character?24 The?Camera?26 Object?Profile:?Main?Camera?27 Continuing?our?Level?28 Script?Profile: CameraTargetAttributes?28 Handling?Rigidbodies?29 Object?Profile:?Crate?30 Exercise?31 Moving?Platforms?32 Object?Profile:?Moving?Platform?33 The?Spaceship?34 Object?Profile:?Spaceship?35 Well?Done!?36 3.Delving?Deeper:?Scripting?Examples
Studying?the?Scripts?38 Moving?Platform?Particle?Effects?38
The?Camera?Scrolling?Script?40 Streamline?Your?Workflow?41 Spaceship?Script?Part?1:?Defining?Helper?Classes?43 Spaceship?Script?Part?2:?Controlling?the?Spaceship?44 Spaceship?Script?Part?3:?Special?Effects?47 Finished!?47 4.What's?Next?
Your?Turn?48
Introduction
Why?2D?is?the?Bee's?Knees
It?is?no?secret?that?Unity?can?help?you?create?great?three-dimensional?games?with?ease.?Its?raw?power?and?flexibility?allows?even?beginners?to?create?impressive?games?with-out?much?difficulty.?Unity?is?undoubtedly?a?great?3D?game?engine?--?so?why?on?earth?would?you?want?to?create?a?2D?game?with?it?
For?certain?game?types,?that?extra?"D"?in?3D?can?be?a?hindrance.?Some?games?simply?work?better?with?two-dimensional?gameplay?mechanics.?Think?of?those?simple?and?fun?2D?side-scrolling?games?you?have?played?in?the?past,?or?maybe?you?have?a?simple?puz-zle?game?idea?that?would?work?best?constrained?to?two?dimensions?--?the?list?keeps?going?but?the?bottom?line?is?many?games?can?benefit?by?the?use?of?only?two?dimen-sions.?
Two-dimensional?games?are?also?commonly?easier?for?the?casual?gamer?to?understand,?which?is?something?to?consider?if?you're?a?small?game?developer?(see?the?article?"Cas-ual?Games?as?a?Business").
Luckily,?Unity?is?extremely?flexible?and?can?easily?handle?2D?gameplay!?Its?world?class?Ageia?PhysX?is?highly?adaptable?and?can?be?constrained?in?many?ways?including?two?dimensions.?
In?this?tutorial?we?define?a?2D?Game?as?a?game?where?graphics?are?still?in?3D,?but?re-stricted?motion?causes?the?physics?and?gameplay?only?to?occur?in?a?single?2D?plane.?This?lets?us?use?3D?models?for?our?content?and?makes?life?easier?for?artists?and?devel-opers?alike.?One?could?say?that?we're?using?the?best?of?both?worlds:?the?ease?of?2D?Sometimes?2D?gameplay?
calls?and?you?can't?resist?its?
alluring?charm!?Unity?can?
handle?it.?
This?tutorial?shows?the?
steps?you?need?to?create?a?
basic?2D-style?platform?
game.
gameplay?and?the?beauty?of?3D?graphics?--?with?the?added?attraction?that?existing?de-velopers?already?have?a?good?3D?asset?production?pipeline?in?place.?
This?tutorial?will?guide?you?in?building?a?2D?platform?game.?We?have?designed?this?tutorial?with?beginner?/?intermediate-level?users?in?mind;?we?only?ask?that?you?have?a?baseline?knowledge?of?Unity.?We?have?also?included?some?advanced?concepts?that?may?be?of?interest?to?more?seasoned?users.?
We?begin?by?getting?you?into?the?2D?mind-set.?Then?we?will?walk?you?through?build-ing?a?2D?world?in?which?your?character?will?move?around.?After?adding?a?few?cool?ob-stacles?and?scenery,?we'll?lastly?add?a?rocket?ship?for?the?player?to?fly.?
We?hope?you?enjoy?this?tutorial?as?much?as?we?had?fun?creating?it!
The?tutorial’s?demo?level?in?action.
Prerequisites
Here?are?the?tools?and?knowledge?you?should?have?before?you?begin?this?tutorial:?Unity?2
Although?you?can?benefit?from?this?tutorial?if?you're?a?Unity?1.x?user,?there?are?some?features?we?use?within?this?tutorial?that?are?only?found?in?Unity?2.0?and?above.
?Basic?Scripting.?
We?assume?that?you?already?have?a?grasp?of?basic?scripting?principles.
?Familiarity?with?the?Unity?user?interface.?
You?should?also?be?familiar?with?Unity’s?key?interface?elements,?such?as?the?Inspector,?the?various?Views,?and?basic?drag-and-drop?techniques.?If?you?are?unfamiliar?with?Unity,?please?take?a?look?at?our?“Introduction?to?Unity”?videos.?You’ll?find?these?in?our?website’s?Resources?area.
?3D?Modeling?Tools?(Recommended).?
Although?not?required?since?we?supply?the?models,?it?is?recommended?that?you?have?tools?to?examine?the?3D?assets.?Such?tools?include?Autodesk?Maya?8,?3D?Studio?Max,?Cinema?4D,?and?Cheetah3D.?(NOTE:?Blender?can?export?FBX?files,?but?cannot?currently?import?this?format.)
?2D?Graphics?Tools?(Recommended)?
Again,?it?is?not?required?but?we?recommended?that?you?have?tools?to?examine?the?2D?assets?we?supply.?Such?tools?may?include?Adobe?Photoshop,?Corel?Painter,?or?one?of?the?budget?alternatives?such?as?Pixelmator.
Also,?be?sure?to?download?the?project?file?meant?to?accompany?this?tutorial.?You’ll?find?the?files?in?our?Resources?section:?https://www.wendangku.net/doc/da4922395.html,/support/resources/
Setting?The?Scene
This?section?of?the?tutorial?will?mostly?deal?with?how?to?set?up?GameObjects?in?the?scene?view,?adding?Components,?and?how?to?manipulate?them?in?the?Inspector.?We?provide?you?with?a?relatively?empty?scene?and?your?mission?is?to?build?onto?that?scene?to?make?up?a?more?complete?level.?Bottom?line?is,?we?are?providing?the?tools?you?need?and?you?need?to?use?them?to?construct?a?level.?Later?on?in?this?tutorial?we?delve?a?bit?deeper?and?explain?how?some?of?the?specific?scripts?work.
Getting?in?the?2D?Mind-Set
Now?we?need?to?get?in?the?proper?mind-set?and?create?some?common?conventions?that?will?remain?consistent?throughout?our?project.?First?we?need?to?define?our?plane?of?motion.?In?other?words,?we?need?to?restrict?motion?to?only?two?of?the?three?dimen-sions,?traditionally?named?X,?Y,?and?Z.?To?do?this?we?must?specifically?decide?which?axis of?motion?will?have?no?movement.?
TIP When?in?the?Scene?View?you?can?remember?which?color?correlates?to?which?
axis?with?the?simple?mnemonic?device?"RGB?=?XYZ"?
The?usual?convention?is?for?the?X-axis?to?correspond?to?horizontal?movement?relative?to?the?observer,?while?the?Y-axis?corresponds?to?vertical?movement.?The?Z-axis?there-fore?corresponds?to?movements?towards?and?away?from?the?observer?--?for?our?pur-poses,?this?means?the?Z-axis?corresponds?to?motion?towards?and?away?from?our?cam-era.
Throughout?the?tutorial?let’s?keep?the?following?in?mind:It’s?time?to?prepare?for?our?
journey.?
In?this?section?we?start?
putting?our?scene?together?
and?look?at?how?Unity?can?
be?made?to?handle?2D?
games.
?Defining?our?Plane?of?Motion.
We?are?going?to?stick?with?common?convention?and?have?our?motion?be?in?the?X-Y?plane,?meaning?that?no?movement?will?occur?in?the?Z-axis.?Vertical?movement?will?be?in?the?Y-axis?and?horizontal?movement?will?be?in?the?X-axis.
?Restricted?Rotation.?
We?also?need?to?restrict?our?rotation.?As?a?general?rule,?the?only?rotation?that?we?will?allow?is?rotation?around?the?Z-axis.?Remember?the?Z-axis?passes?through?the?camera;?therefore?rotation?around?the?Z-axis?will?result?in?clockwise?and?counterclockwise?ro-tation?as?the?Main?Camera?sees?it.?There?is?one?exception?to?this?restricted?rotation,?however.?The?character?is?allowed?rotation?about?the?y-axis?so?he?can?turn?from?side?to?side.
A?2D?game?needs?just?two?axes:?X?and?Y.
With?all?this?in?mind,?it's?finally?time?to?open?our?project?and?scene.?If?you?haven't?al-ready?done?so,?please?download?the?project?files?now.?
Select?File->Open?Project?and?locate?the?2D?Tutorial?project?that?you?have?down-loaded.?
Once?you?have?opened?the?project,?find?the?scene?2D?Platformer?in?the?Project?
Pane?and?open?it.?
Play?the?Scene.
The?2D?Platformer?Scene.
Controls
Use?the?cursor?keys?to?move?Lerpz.?Hold?down?the?Ctrl?key?to?make?him?run?and?use?the?space?bar?to?jump.?
The?GUI?buttons?at?the?top?toggle?between?controlling?the?character?and?the?space-ship.?Everything?in?this?scene?has?already?been?laid?out?for?you.?Feel?free?to?explore?and?examine?everything?you?can.?The?more?familiar?you?are?with?how?we?set?up?our?level,?the?easier?it?will?be?to?create?your?own.?
A?Closer?Look
Here?are?two?things?you?can?investigate?to?better?understand?how?to?set?up?a?2D?game?before?you?do?it?yourself:
Object?Positions?
If?you?bring?up?an?element?in?the?Inspector,?you’ll?see?that?all?objects?are?placed?at?zero?in?the?Z-axis,?keeping?to?the?convention?we?defined?above.?
When?modeling?your?3D?assets,?it?may?make?your?life?easier?to?model?them?in?your?modeling?application?with?the?same?orientation?as?in?Unity.?Although?not?crucial,?this?avoids?the?inconvenience?of?having?to?rotate?them?after?you?import?them.
Platform?Tiling?
If?you?investigate?the?platforms?in?this?scene?you'll?notice?that?they?are?made?up?of?smaller,?tile-able?pieces,?with?end-caps?for?the?beginnings?and?ends?of?platforms.?This?can?save?hours?of?modeling?time?so?platforms?can?be?built?within?Unity?and?easily?changed.?Everything?from?the?size?to?the?textures?are?modeled?with?tiling?in?mind.?
NOTE?Tiling?was?a?very?common?technique?in?the?early?days?of?computer?games.?It?had?the?very?useful?advantage?of?reducing?the?amount?of?graphical?assets?re-
quired,?keeping?the?project’s?overall?size?down.?In?the?days?when?computer?
memory?was?measured?in?kilobytes,?this?was?an?important?factor.?Today,?tiling?remains?a?useful?technique?as?it?reduces?both?asset?production?time?and?down-load?size.?
Setting?the?Level?Attributes
After?playing?our?pre-built?level,?it's?time?to?begin?our?own.?
Create?a?new?scene?by?going?to?File->New.?You?now?have?a?completely?empty?scene?that?is?ready?to?rock.?Before?you?begin,?make?sure?that?your?interface?is?set?up?how?you?prefer.?Be?sure?that?the?Scene?View,?Project?Pane,?Hierarchy?Pane,?and?Inspector?are?all?present.
First?thing?to?do?is?to?define?our?Skybox:?
Go?to?Edit->Render?Settings?in?the?menu.?In?the?Inspector,?you?should?see?an?
empty?slot?for?a?Skybox.?
In?the?Project?Pane,?expand?the?folder?Standard?Assets->Skyboxes.?
Drag?Martian?Stratosphere?into?the?Skybox?Material?slot?in?the?Inspector?for?the?Render?Settings.?
The?Render?Settings
Now?we?should?have?a?nifty?skybox?that?we?will?see?in?the?background?at?all?times?in?our?game.
The?Game?View,?showing?the?Skybox.
Next,?we?need?to?add?something?which?will?manage?some?important?attributes.?
Look?in?the?Project?Pane?and?find?the?Prefab?named?Level?Attributes?within?the?Level?Prefabs?folder.?
Drag?the?Prefab?into?the?Hierarchy?Pane?so?it?is?loaded?in?your?scene.?
Ensure?that?its?Position?is?at?(0,?0,?0).?This?will?make?life?easier?in?the?long?run?for?the?child?object?"Death?Zone."
The?Level?Attributes?Prefab?in?the?Scene?View.?We?see?two?new?objects?here:?the?small?rectangle?rising?up-wards?defines?the?level’s?boundaries.?The?long?oblong?lying?flat?is?the?“Death?Zone”?(displaying?the?skull).
In?the?Scene?View?you?should?now?be?able?to?see?a?green?rectangle?that?represents?the?size?of?your?level.?If?you?cannot?see?the?green?rectangle,?adjust?your?viewing?position?so?that?you?can?clearly?see?it.?
Adjust?the?settings?according?to?how?big?you?want?your?level?to?be.?
As?a?reference?point,?the?completed?level?that?we?supplied?was?44.25?units?wide?
by?60?units?tall.?Make?sure?that?everything?is?located?at?zero?in?the?Z-axis.?The?
size?of?your?level?can?easily?be?changed?later?so?don’t?worry?about?getting?it?ab-
solutely?right.
Finally...
SAVE?your?scene!
So?what’s?going?on?here??Lets?take?a?much?closer?look?at?the?Level?Attributes?and?Death?Zone?GameObjects...
Object?Profile:?Level?Attributes
The?Level?Attributes?object?started?as?an?empty?GameObject?at?position?(0,?0,?0).?The?script?LevelAttributes?has?been?applied?to?it.
Functions
?OnDrawGizmos()?
Displays?the?level’s?dimensions.?The?level’s?size?is?denoted?by?the?green-bordered?rec-tangle?drawn?in?the?scene?view.?
?Start()
Creates?physics?Colliders?at?startup?that?act?as?borders?around?the?world?to?prevent?
the?character?from?leaving?the?level?boundaries.
Script:?LevelAttributes
This?script?defines?the?level’s?key?attributes?based?on?the?values?you?set?in?the?Inspec-tor:
?Bounds
?X:?The?x-coordinate?that?your?level?will?start?at.
?Y:?The?y-coordinate?that?your?level?will?start?at.
?Width:?The?width?of?your?level?starting?at?the?X-coordinate?above.
?Height:?The?height?of?your?level?starting?at?the?Y-coordinate?above.
?Fall?Out?Buffer: This?creates?a?buffer?zone?at?the?bottom?of?your?level.?Its?purpose?is?to?give?your?character?some?room?to?fall?without?the?camera?following?until?it?hits?the?bottom?Collider.
?Collider?Thickness: The?thickness?of?the?Colliders?that?create?your?borders.
Further?Analysis
If?you?select?the?LevelAttributes?GameObject?after?pressing?play,?then?look?at?the?green?boundary?rectangle?in?the?scene?view,?you?will?notice?Colliders?(represented?by?light?green?boxes)?at?the?edges.?These?are?the?automatically-generated?physics?Collid-ers?created?by?the?LevelAttributes?script.
Object?Profile:?Death?Zone
The?Death?Zone?object?started?as?an?empty?GameObject?at?position?(0,?0,?0).?It?is?a?child?object?of?Level?Attributes.?It?does?not?need?to?be?a?child?of?Level?Attributes,?but?for?organizational?purposes?works?well?there.?The?script?"DeathTrigger"?has?been?ap-plied?to?it.
Function
Provides?a?Collider?--?defined?as?a?Trigger?--?which?causes?the?character?to?re-spawn?if?he/she?falls?onto?it.?This?is?useful?for?pits?that?the?player?can?fall?into.
Script:?DeathTrigger
This?script?draws?the?little?skull?and?crossbones?that?you?see?in?the?scene?view?by?tak-ing?advantage?of?Gizmo?icons.?Although?it's?not?necessary,?it?is?useful.?(“Setting?Up?the?Platforms”?has?more?information?on?Gizmos.)
Setting?Up?the?Platforms
Now?it's?time?to?create?the?foundation?of?our?level:?the?platforms.?
In?the?Project?Pane?you?will?see?a?prefab?called?"Pre-Assembled?Platform."?Drag?
it?into?the?Scene.?
Ensure?the?platform?is?located?at?zero?along?the?z-axis.?
Position?the?platform?in?a?place?you're?happy?with.?
Placing?the?Pre-Assembled?Platform?Prefab.
This?platform?was?pre-assembled?for?you,?but?you?will?have?to?make?the?rest?yourself.?
Look?in?the?Hierarchy?Pane?and?you'll?see?that?the?Pre-Assembled?Platform?has?several?child?objects.?These?children?objects?are?what?make?up?the?platform.?If?you?investigate?the?platforms?you'll?notice?that?they?are?made?up?of?smaller,?tile-able?pieces,?with?
end-caps?for?the?beginnings?and?ends:
Looking?inside?the?Pre-Assembled?Platform?Prefab.
Using?these?platform?tiles,?create?more?platforms?for?your?character?to?run?wild!?Keep?these?pointers?in?mind:
?Always?make?sure?the?z-position?is?at?zero.
?Look?at?the?pre-assembled?platform?for?reference.
?We?highly?recommend?that?you?parent?groups?of?platform?tiles?together,?for?reasons?described?in?Object?Profile:?Pre-Assembled?Platform,?below.?
To?do?this,?create?an?empty?GameObject?by?going?to?GameObject->Create?Empty?and?name?it?appropriately.?Make?sure?the?GameObject?is?located?at?zero?along?the?Z-axis.?Also?make?sure?that?the?X?and?Y?coordinates?are?where?you?want?the?platform?to?be?located.?Then?you?can?drag?the?platform?tiles?inside?the?empty?GameObject?you?just?created.?Last,?apply?the?script?CombineChildren?so?you?mimic?the?function?of?the?Pre-Assembled?Platform?GameObject?described?above.
?The?tiles?can?be?precisely?positioned?easily?because?their?lengths?are?nice?whole-number?values.
?The?platforms?must?stay?inside?of?the?green?level?boundary?you?set?up?in?the?previous?section!?If?your?platforms?are?outside?this?area?they?will?be?unreachable.?You?can?al-ways?change?the?size?of?the?boundaries.
?Save?frequently!
You?can?always?create?more?platforms?later,?but?you?at?least?want?an?area?that?the?character?can?run?around.?
Object?Profile:?Platform?(Prefabs)
In?the?Project?Pane?you?can?find?these?prefabs?inside?Level?Prefabs/Platforms.?
Functions
These?are?the?tile-able?pieces?that?make?up?the?larger?platforms.?You'll?find?five?dif-ferent?pieces?within?the?Platform?Tiles?folder:
?Platform?-?Level:
A?level?piece?of?platform?that?is?6?units?long.
?Platform?-?Slope?Up:
A?piece?of?platform?that?slopes?up?moving?from?left?to?right.?It?is?3?units?long.
?Platform?-?Slope?Down:
A?piece?of?platform?that?slopes?down?moving?from?left?to?right.?It?is?3?units?long.
?Platform?-?End?Cap?Left:
This?belongs?at?the?left?edge?of?an?array?of?platforms?to?cap?it?off.
?Platform?-?End?Cap?Right:
This?belongs?at?the?right?edge?of?an?array?of?platforms?to?cap?it?off.
The?length?of?these?pieces,?(with?the?exception?of?the?end?caps?since?it?is?not?neces-sary,)?are?nice?whole?numbers?so?they?can?be?precisely?tiled?by?editing?the?numbers?in?the?Inspector.
Components
?Box?Collider
Without?this,?the?character?and?spaceship?would?fall?right?through?the?platform! This?is?needed?to?physically?interact?with?the?character.?The?Box?Collider?size?has?been?ad-justed?to?fit?the?platform?tile,?otherwise?all?settings?are?default.?Since?the?platform?does?not?move?at?all,?we?do?not?have?to?apply?a?Rigidbody?component.
?Pipeline,?Mesh?Filter,?and?Material:
These?assign?the?proper?mesh?and?texture?so?it?renders?in?the?scene.
Script:?CollisionSoundEffect
The?foot?script?attached?to?our?player?checks?GameObject?it?comes?into?contact?with?for?the?presence?of?this?script?and?plays?the?sound?effect?it?holds?(if?you?have?set?one).?In?this?way?our?player?character’s?footsteps?can?be?made?to?sound?different?on?differ-ent?surfaces?--?e.g.?a?metallic?sound?on?metal?platforms;?a?wooden?footstep?sound?on?wooden?surfaces,?and?so?on.
Script:?CollisionParticleEffect
This?script,?like?the?one?above,?provides?a?similar?service?for?particle?effects.?The?player’s?foot?script?looks?to?see?if?we’ve?set?a?particle?effect?GameObject?and?starts?it?if?so.?This?is?how?the?character?raises?the?clouds?of?dust?as?he?runs?around?the?example?level.
TIP?If?you're?curious,?examine?the?texture?(which?is?the?same?for?each?tile)?to?see?how?it?loops.
Object?Profile: Pre-Assembled?Platform
It's?the?parent?object?that?contains?platform?tiles?that?create?a?single?large?platform.
Function:
This?GameObject?serves?two?purposes.?
?As?a?container?used?to?organize?the?level?and
?To?aid?performance?--?see?the?script?described?below.?
It?is?recommended?that?you?structure?your?entire?level?using?this?method.?In?other?words,?for?each?group?of?platform?tiles?that?make?up?a?large?platform,?create?a?parent?object?for?them?with?the?CombineChildren?script?applied.
Script:?CombineChildren
In?the?Inspector?you?can?see?this?script?with?its?self-explanatory?options.?What?this?does?is?take?all?of?the?children?GameObjects?--?i.e.?the?platform?tiles?--?and?combine?their?meshes?so?instead?of?rendering?6?different?objects,?only?1?object?is?rendered.?This?en-hances?performance,?especially?when?you?reach?a?large?number?of?platforms.?
TIP?This?script?actually?comes?in?the?Standard?Assets?package,?which?is?shipped?with?Unity.
Introducing?Lerpz,?Our?Lovely?Character
Lerpz,?our?zany?character,?is?getting?anxious?for?action!
Lets?get?our?spawn?point?set?up?first.?The?spawn?point?is?where?the?character?will?ap-pear?when?you?start?the?game.?It's?pretty?simple?to?do,?just?follow?these?steps:
Create?a?new?empty?GameObject?by?going?to?GameObject->Create?Empty.?Re-
name?it?to?“Character?Spawn?Point”.
Apply?the?script?titled?SpawnPoint?to?the?GameObject?you?just?created.?This?
script?creates?that?little?2D?icon?of?Lerpz?inside?the?Scene?View?so?you?can?see?
where?the?spawn?point?is.?(This?little?drawing?is?called?a?Gizmo.?The?Death?Zone?also?has?one?of?these?to?display?the?skull-and-crossbones?icon.)
Position?the?spawn?point?where?you?want?Lerpz?to?appear.?Make?sure?it?is?at?z?=?0?with?a?platform?underfoot,?so?he?actually?has?a?place?to?stand?when?he?ap-
pears.
What?exactly?is?a?Gizmo?
Gizmos?are?shapes,?icons?and?other?visual?aids?that?appear?in?the?Scene?View?such?as?lines,?lamps,?cameras,?and?audio?sources?to?assist?in?visual?debugging?or?layout.?Giz-mos?drawn?exclusively?in?this?2D?tutorial?are?the?Death?Zone,?and?Character?Spawn?Point.?
All?it?takes?is?a?very?simple?script.?Here's?an?example?of?the?script?SpawnPoint?that?is?applied?to?the?Character?Spawn?Point:
function OnDrawGizmos()
{
Gizmos.DrawIcon(transform.position, "Player Icon.tif");
}
Gizmo?icons?must?be?placed?in?the?Assets/Gizmos?folder.?
The?LevelAttributes?script?also?takes?advantage?of?Gizmos:?The?green?border?you?see?representing?the?level?boundaries?is?a?Gizmo.?For?a?complete?reference?on?Gizmos,?you?can?refer?to?the?documentation?
(https://www.wendangku.net/doc/da4922395.html,/Documentation/ScriptReference/Gizmos.html).
Placing?Lerpz
The?next?step?is?to?add?Lerpz?himself?to?our?Scene:
Drag?the?Prefab?"Character?(Lerpz)"?in?our?Level?Prefabs?directory?into?the?
Scene.?Since?we?have?a?spawn?point?set?up,?you?can?place?him?anywhere?you'd?like,?just?as?long?as?he's?somewhere?in?the?Scene.?
If?it’s?not?already?visible,?bring?up?our?Character?in?the?Inspector?and?open?up?
the?Platform?Controller?Script?Component.?Note?the?Spawn?Point?slot:
Character?(Lerpz)?with?no?Spawn?Point?set.
Drag?our?earlier?Character?Spawn?Point?object?into?this?slot,?so?it?looks?like?this:
Character?(Lerpz)?with?the?Spawn?Point?set.
The?next?step?is?to?get?the?Main?Camera?to?follow?Lerpz?around...
Directing?the?Camera
At?the?moment,?our?main?camera?will?simply?sit?where?it?is?and?point?at?whatever?it’s?aimed?at.?Much?like?in?a?movie?or?TV?production,?we?need?to?direct?the?camera?--?tell?it?how?to?move,?when?to?do?so?and?what?it?should?be?aimed?at.?We?achieve?this?with?two?scripts:
Drop?the?CameraScrolling?script?(from?Scripts->2D->Camera)?onto?the?Main?
Camera?GameObject.
Drop?the?CameraFocus?script?(from?the?same?location)?onto?the?Main?Camera. The?next?step?is?to?give?the?scripts?the?information?they?need?to?work:
Select?the?Main?Camera?in?the?Hierarchy?Pane?and?open?up?the?CameraFocus?
script?Component?in?the?Inspector.
Open?the?Targets?group?and?change?Size?to?1.?Element?0?should?appear?below?it.
Drag?our?Character?(Lerpz)?GameObject?onto?the?Element?0?slot.
Open?the?Target?Button?Names?group?and?change?Size?to?1.?(Again,?Element?0?should?appear.)?
Type?“Player”?into?Element?0’s?slot.
The?result?should?look?like?the?image?below:
Setting?up?the?Camera?Focus?script?component.
We?should?now?have?a?working?camera?and?character?running?and?jumping?over?our?platforms.
It?was?very?easy?to?get?the?character?in?the?level?using?Prefabs,?but?on?closer?inspection?Lerpz?is?anything?but?simple:
Object?Profile:?Character?(Lerpz)
Lerpz?is?the?main?character?of?our?game.?He?can?walk,?run,?jump,?and?fall.?He?moves?around?our?level?wreaking?havoc?wherever?he?goes.
Components
?Animation
This?component?stores?a?list?of?animations?for?the?character?that?can?be?accessed?by?scripting.?PlatformPlayerAnimation?(listed?below)?makes?use?of?this?component?by?ac-cessing?different?animations.
?Character?Controller?
The?traditional?side-scrolling?character?controls?are?generally?not?physically?realistic.?The?character?comes?to?a?halt?immediately?and?turns?on?a?dime,?making?it?difficult?and?impractical?to?use?Rigidbody?physics.?As?a?result,?we?use?an?alternate?method?to?move?the?character?around?by?using?the?Character?Controller.?See?more?detail?on?this?com-ponent?in?the?documentation.?
(https://www.wendangku.net/doc/da4922395.html,/Documentation/Components/class-CharacterController.html)
Script?Applied:?PlatformerController
This?script?is?a?custom?script?made?for?this?2D?tutorial.?This?script,?in?cooperation?with?the?CharacterController?component,?is?used?to?define?its?physical?mechanics?within?our?world.?Most?of?the?adjustable?settings?are?self-explanatory?and?we?will?not?go?into?much?detail,?but?a?few?require?some?further?discussion: