- Home /
Scroll to change walk speed...
I have 3 floats in my movement script. Each is called like so: speed, minSpeed and maxSpeed. I want to be able to scroll up to add to the speed float, and scroll down to subtract from it. The min and max speeds are so it does not reach anything beyond or behind the boundaries I have set. However, as I have concluded from many failed attempts, I cannot seem to work the bit with the scrollwheel. I have tried many, but many failed me. Can anyone assist me with the scrolling?
Thanks in Advance!
Answer by Professor Snake · Feb 21, 2013 at 08:40 PM
You can use Input.GetAxis("Mouse ScrollWheel").
function Update(){
if((Input.GetAxis("Mouse ScrollWheel") > 0&&speed < maxSpeed)||(Input.GetAxis("Mouse ScrollWheel")< 0&&speed > minSpeed)){
speed+=Input.GetAxis("Mouse ScrollWheel");
}
Note the += in the code. Input.GetAxis("Mouse ScrollWheel") returns values from -sensitivity to +sensitivity in each frame. Assuming the sensitivity is 0.1 (which i think is the default value), setting speed to be equal to the axis would only make speed equal to values from -0.1 to 0.1. Alternatively, for a relatively smoother approach, you could detect whether GetAxis("Mouse ScrollWheel") is positive or negative. If it's positive, increment speed by 1 (instead of the axis' value). If it's negative, decrease it by 1. Make sure that the axis is properly set up at the input manager.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Change int value for 30 sec... 1 Answer
Player controls for scrolling horizontally/vertically? 0 Answers
Rigidbody speed / Velocity issue 0 Answers
How do I make a scene change when my Player collides with a item? 1 Answer