- Home /
Mouse Wheel Zoom code not working like it should
I have an RTS style top-down / isometric view control scheme that I am attempting to work on.
So far I have WASD and Keypad controlling movement going Left, Right, Forward, and Backwards.
I am attempting to add a "Zoom" function to "Mouse Scrollwheel" that effects the FOV of the camera. The code I have SHOULD work, yet it's not doing anything. And yes, I have tested, my Mouse Wheel works just fine.
Here is my code (including Keyboard Movement):
// Camera Scroll Speed var scrollSpeed : float = 20.0;
function Update () {
var fwdBack : float = Input.GetAxis ("Vertical") * scrollSpeed;
var leftRight : float = Input.GetAxis ("Horizontal") * scrollSpeed;
fwdBack *= Time.deltaTime;
leftRight *= Time.deltaTime;
transform.Translate (leftRight, 0, 0);
transform.Translate (0, 0, fwdBack);
// Mouse Scroll Wheel Zoom
//------------------Code for Zooming Out------------
if (Input.GetAxix("Mouse ScrollWheel") <0)
{
if (Camera.main.fieldOfView<=100) {
Camera.main.fieldOfView +=2; }
if (Camera.main.orthographicSize<=20) {
Camera.main.orthographicSize +=0.5; }
}
//----------------Code for Zooming In-----------------------
if (Input.GetAxis("Mouse ScrollWheel") > 0)
{
if (Camera.main.fieldOfView>2) {
Camera.main.fieldOfView -=2; }
if (Camera.main.orthographicSize>=1) {
Camera.main.orthographicSize -=0.5; }
}
}
Answer by Mij · Sep 11, 2013 at 01:27 AM
// Mouse Scroll Wheel Zoom
//------------------Code for Zooming Out------------
if (Input.GetAxis("Mouse ScrollWheel") <0)
{
if (Camera.main.fieldOfView<=100) {
Camera.main.fieldOfView +=2; }
if (Camera.main.orthographicSize<=20) {
Camera.main.orthographicSize +=0.5; }
}
Input.GetAxis was Input.GetAxix
Works for me when I changed it. If it's not there, try adding '#pragma strict' to the top of your code. Should have the compiler catch that sorta thing. Best of luck!