- Home /
Question by
oliver-jones · Feb 24, 2011 at 05:19 PM ·
javascriptconvertmouselook
Convert From C# Into JavaScript Please?
Hello,
I'm using the Unity 'MouseLook', but its in C#, and I only know (work with) JavaScript. If someone could be kind enough to convert this into javascript, then that would be great! (Its slightly modified)
using UnityEngine; using System.Collections;
[AddComponentMenu("Camera-Control/Mouse Look")] public class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
public static bool headLock = false;
void Update ()
{
if (axes == RotationAxes.MouseXAndY && headLock == false)
{
float rotationX = 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 && headLock == false)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else if (axes == RotationAxes.MouseY && headLock == false)
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
print("HEADLOCK-C# = "+headLock);
if(Input.GetButton("Jump") || SelectControl.toggleClick == true){
headLock = true;
print("headLockC# = true");
}
else{
headLock = false;
print("headLockC# = false");
}
}
void Start ()
{
headLock = false;
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
}
Thanks!
Comment
Do look up on the basic differences between C# and Javascript. That code only has a few things that need to be changed.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110057im_/https://answers.unity.com/themes/thub/images/avi.jpg)