Game Development Reference
In-Depth Information
public var minimumY : float = -60;
public var maximumY : float = 60;
private var rotationY : float = 0;
public function Start () : void {
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
public function Update () : void {
if (axes == RotationAxes.MouseXAndY)
{
var rotationX : float = transform.localEulerAngles.y + Input.
GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX,
0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.
localEulerAngles.y, 0);
}
}
This script is the JavaScript version of the MouseLook built-in script. This
way we can edit and adapt the script without bothering anything in the built-
in script. Even though, in Unity we can use both C# and JavaScript languages
in the same project (we will talk about this in more detail in Chapter 8, Let
the World See your Carnage! Saving, Loading, and Posing your High Score ),
it's beter to pick one language for the enire project because it will be very
difficult to access the parameters between different languages.
 
Search WWH ::




Custom Search