2019-06-01 net

(Brent) #1

Unity


Unity User Manual
https://docs.unity3d.com/Manual/index.html
The Unity User Manual includes detailed documents on
every aspect of the user interface, tools and platforms. The
comprehensive scripting API contains syntax and examples for
virtually every function and command in the Unity C# language.
The integration in the scripting environment (Visual Studio) makes
jumping into the docs seamless.

Unity Tutorials
https://unity3d.com/learn/tutorials
The video tutorials found here are an indispensable resource for
getting started with Unity. Whether jumping into game dev or
building out a site concept to export to WebGL, there are tips and
tricks to make learning quick. Step-by-step examples walk through
almost every aspect of the process.

Unity Developer Forums
https://forum.unity.com/
Unity has an enormous developer community, so one of the best
resources to tap – once you’ve explored the docs and tutorials – is
the forums.

WebGL Integration
https://docs.unity3d.com/Manual/webgl-
interactingwithbrowserscripting.html
After you’ve mastered the basics, Unity also includes an interface
for communicating between JavaScript running on your page and
a WebGL instance. This enables you to fit Unity WebGL in as you
need; as a complete solution or a single piece to a larger web-
based application.

Essential Resources


RESOURCES

panel. Update its position to 0,0,-1 to centre it on
the screen. Scale as required to fill about 5% of the
vertical screen space. We’ve set the z to -1 so this
sprite sits in front of the sky, which we’ve already
sized perfectly to fill the screen.
If you test the game now, the plane will be sitting
in the middle screen with the background flying by.


STEP 11: 2D PHYSICS
The next thing we want to do is get gravity to affect
our plane, by adding it to the physics model in Unity.
Start by removing any default components for
Rigidbody or Collider that may be already attached
to your sprite. You can see these components in
the Inspector view when you select the your sprite.
There is a little gear icon in the upper right of each
component that lets you remove it.
Now add a Collider component. You want it to be
a 2D collider since our 2D game will use 2D physics.
Select Add Component>Physics 2D>Box Collider 2D.
Also add a Rigidbody 2D component.
On the Rigidbody 2D component, set the body type
to Dynamic and the Gravity Scale to 3. Adjust this as
you like but I found it matched the heavy gravity I
wanted and avoided the plane having too much float
or hang time after it moved upwards. Make sure
Simulated is checked and Mass is set to 1.
You should edit the Collider so it matches your
sprite shape. Click the Edit Collider button on the
component. Use the resize handles to adjust the
outline to match your sprite. This is the shape the
physics engine will use to calculate collisions. If you
try out your game now, you should see the plane fall
with gravity physics, off the bottom of the screen.


STEP 12: ADD A CHARACTER
CONTROLLER SCRIPT
Next, create a script to control your character.
Click the Add Component button and create and
add a new script to the plane game object. Call it
‘planeController’, then double-click it to open and
edit in Visual Studio as before.
We’ll add some rotation to the plane based on its
velocity, so once we hook up some controls, it will
have a little animation in the direction it flies. To
do this, change your Update function to look like the
following code:


void Update() {
Rigidbody2D rb = GetComponent();
float rot = rb.velocity.y;
Quaternion target = Quaternion.Euler(0.0f, 0.0f,
rot3.0f);
transform.rotation = Quaternion.Slerp(transform.
rotation, target, Time.deltaTime
5.0f);
}

Free download pdf