Game Development Reference
In-Depth Information
Classified Intel
In this step, we have access to the Character Motor and can change MouseLook script to
MouseLook_JS script. If we take a look at the Character Motor script, we will see that
it has a lot of parameters to adjust. In our case, we only pass the inputMoveDirection ,
inputJump , movement.maxForwardSpeed , movement.maxSidewaysSpeed , and
movement.maxBackwardsSpeed parameters. We don't need to go to every parameter in
the Character Motor , but there is something that we will need to know to be able to use
it with our script. The Character Motor will help us to calculate the smooth movement
speed including moving forward, backward, and sideways. It will calculate the gravity when
the character is jumping and falling as well as check for the moving plaform.
Next, we will take a look at the MouseLook script. If we open up this script, we will see that it is
writen in C#, but we need not worry as Unity allows us to access the parameters even though
we are using JavaScript. As we know, we can use C# (and also Boo) scriping language to write
the script in Unity similar to JavaScript. So, let's open the MouseLook and look inside—it's
very similar to what we did for MouseLook_JS in JavaScript. However, there are numerous
diferences between wriing JavaScript and C#, but we will talk about the basics of syntax.
Both of the preceding scripts do the same thing, but use different syntaxes. For example, if
we want to create a float variable in JavaScript, we can use the following line of code:
public var myNumber : float = 0;
To create a funcion we can use the following line of code:
public function Myfuncion () : void { //dosomething }
On the other hand, if we are using C#, we can write the following line of code:
public float myNumber = 0F;
We put the F here to tell the complier
that it is a float value.
And for the funcion, we will use the following line of code:
public void Myfuncion () { //dosomething }
There is also some diference in syntax between both the languages. For more informaion,
we can go to the following websites:
http://unity3d.com/support/documentation/ScriptReference/index.
Writing_Scripts_in_Csharp.html
http://answers.unity3d.com/questions/12911/what-are-the-syntax-
differences-in-c-and-javascrip.html .
 
Search WWH ::




Custom Search