void Update () {
if(Input.GetAxis("Mouse ScrollWheel") < 1 Input.GetAxis("Mouse ScrollWheel") != 0){
cam.transform.Translate(new Vector3(0,0,-1));
Debug.Log("Mouse ScrollWheel Back");
}
if(Input.GetAxis("Mouse ScrollWheel") > 1 Input.GetAxis("Mouse ScrollWheel") != 0){
cam.transform.Translate(new Vector3(0,0,1));
Debug.Log("Mouse ScrollWheel Forward");
}
}
Doesn’t seem wrong does it? Well my Mouse ScrollWheel Forward never occurs, rather the Back one ALWAYS does whenever I move my wheel at all.
Why?
Thanks
Myx
April 8, 2012, 8:07am
2
Hello there!
Input.GetAxis returns a result between -1 and 1, therefor it will never be larger than 1. Try instead checking if the result is smaller or larger than 0.
Wow. Such an easy fix. Maybe 1:30am is a good time to stop programming
Thanks man.
For anyone who it may help, this is the working code:
if(Input.GetAxis("Mouse ScrollWheel") < 0 Input.GetAxis("Mouse ScrollWheel") != 0){
cam.transform.Translate(new Vector3(0,0,-0.5f));
Debug.Log("Mouse ScrollWheel Back");
}
if(Input.GetAxis("Mouse ScrollWheel") > 0 Input.GetAxis("Mouse ScrollWheel") != 0){
cam.transform.Translate(new Vector3(0,0,0.5f));
Debug.Log("Mouse ScrollWheel Forward");
}