I’m in the process of creating a small options screen which contains a slider which I want to directly affect the sensitivity of the FPS controller. Since I have multiple cameras, and they all have mouse look scripts, is there a way to affect the core input settings of the program so I don’t have to go around referencing each camera/mouselook script manually?
This is something where it would be appropriate to set a static variable, and then have the mouselook script multiply input by that static variable.
–Eric
I just realised that the mouselook script is written in C# and my scripts are all in js.
I’m having trouble passing variables between the two. Is there an example I can follow somewhere?
you can’t pass variables between C# and JS, you can only access in one direction, given one of the two is in an earlier buildtstep (see the advanced topics in the manual)
I re-wrote MouseLook in js a while ago for that reason:
@script AddComponentMenu ("Camera-Control/Mouse Look")
enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
var axes = RotationAxes.MouseXAndY;
var sensitivityX : float = 15;
var sensitivityY : float = 15;
var minimumX : float = -360;
var maximumX : float = 360;
var minimumY : float = -60;
var maximumY : float = 60;
var rotationX : float = 0;
var rotationY : float = 0;
private var originalRotation : Quaternion;
function Update () {
if (axes == RotationAxes.MouseXAndY) {
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
rotationY = ClampAngle (rotationY, minimumY, maximumY);
var xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
var yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
}
else if (axes == RotationAxes.MouseX) {
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
transform.localRotation = originalRotation * xQuaternion;
}
else {
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = ClampAngle (rotationY, minimumY, maximumY);
yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
transform.localRotation = originalRotation * yQuaternion;
}
}
function Start () {
if (rigidbody)
rigidbody.freezeRotation = true;
originalRotation = transform.localRotation;
}
static function ClampAngle (angle : float, min : float, max : float) : float {
if (angle < -360.0)
angle += 360.0;
if (angle > 360.0)
angle -= 360.0;
return Mathf.Clamp (angle, min, max);
}
–Eric
Eric, thanks loads for sharing. Haven’t tried it yet but cheers in advance.
Edit: Implemented and works perfectly.
Thank you eric!