- Home /
Question by
SamMetalWorker · Dec 12, 2020 at 07:17 AM ·
inputmouseinput.getaxisinput.getkeymousewheel
How to handle Key + Mouse Wheel simultaneously?
My camera code now looks like this:
private void Update()
{
float zoomDelta = Input.GetAxis("Mouse ScrollWheel");
if(zoomDelta != 0f)
{
AdjustZoom(zoomDelta);
}
}
I want to bind camera zoom to Ctrl + Wheel because I want to bind a wheel to brush size in my map editor. The problem is both Input.GetAxis(string)
and Input.GetKeyDown(KeyCode)
don't work simultaneoulsy.
Comment
Best Answer
Answer by SamMetalWorker · Dec 12, 2020 at 07:24 AM
Turns out should use Input.GetKey(KeyCode)
instead of Input.GetKeyDown(KeyCode)
. Final code:
private void Update()
{
if (Input.GetKey(KeyCode.LeftControl))
{
float zoomDelta = Input.GetAxis("Mouse ScrollWheel");
if (zoomDelta != 0f)
{
AdjustZoom(zoomDelta);
}
}
}
Your answer
Follow this Question
Related Questions
Input returns 0 until released and pressed again if held down before start of scene 0 Answers
Input.GetKeyDown, Input.GetKeyUp, and mouse wheel do not work while playing in the editor. 0 Answers
Erratic mouse Input.GetAxis values on OS X 0 Answers