A quick example
Before we dig deep into the theory, let's take some time to make a class and see it in action.
First, we will need to create a sphere in our Hierarchy view:
- Click on the
Create
button. - Hover over 3D object and click on sphere.
- Name the sphere
Ball
. - In the Inspector, make sure that all position elements are 0. Alternatively, you can simply click on the gear icon and select
reset
. - With the sphere reset, change its
position.x
to3.05
,position.y
to0.87
, andposition.z
to4.15
.
Now, we will add a script file to the ball:
- Click on the
Add Component
button in the Inspector. - Scroll down to
New Script
and click on it. - Name the script
LaunchBall;
click onCreate
and then onAdd
. - Double-click on the
Launchball
script in the Inspector.
Visual Studio should be loading now. Once it is loaded, you should see a blank class called LaunchBall
with two using statements and two methods, Start
and Update
. Now, we will need to copy or type the following code into that class.
Let's take a look at Part 1 of...