so i currently have the scrollwheel in game as a zoom in and out, is there a way to press down on the scrollwheel button and at the same time then use the scrollwheel to do something different than zoom,like when scroll forward display image for one weapon then when scroll back change image to second weapon, bit stuk with this one guys, help would be much appreciated thank you
trying this code but cant get it to work, is it not possible to use the scrollwheel when button is down for something different than when button is up?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mscroll2 : MonoBehaviour {
public int roller=0;
public int roller2=0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (!Input.GetKeyDown(KeyCode.Mouse2) && Input.GetAxis("Mouse ScrollWheel") > 0f ) // forward
{
roller++;
}
else if (!Input.GetKeyDown(KeyCode.Mouse2) && Input.GetAxis("Mouse ScrollWheel") < 0f ) // backwards
{
roller--;
}
roller=roller;
if (Input.GetKeyDown(KeyCode.Mouse2) && Input.GetAxis("Mouse ScrollWheel") > 0f ) // forward
{
roller2++;
}
else if (Input.GetKeyDown(KeyCode.Mouse2) && Input.GetAxis("Mouse ScrollWheel") < 0f ) // backwards
{
roller2--;
}
roller2=roller2;
}
}
Its likely you want to use Input.GetKey rather than Input.GetKeyDown.
Input.GetKey will return true while its held, Input.GetKeyDown will only return true on the frame it starts being pressed.
ok changed code to below, but still when roll mouse wheel with button held down still roller increases but not roller2, i need roller to increase when button up and roller2 to increase when button down and roll scrollwheel, can this not be done
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mscroll3 : MonoBehaviour {
public int roller=0;
public int roller2=0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (!Input.GetKey(KeyCode.Mouse2) && Input.GetAxis("Mouse ScrollWheel") > 0f ) // forward
{
roller++;
}
else if (!Input.GetKey(KeyCode.Mouse2) && Input.GetAxis("Mouse ScrollWheel") < 0f ) // backwards
{
roller--;
}
roller=roller;
if (Input.GetKey(KeyCode.Mouse2) && Input.GetAxis("Mouse ScrollWheel") > 0f ) // forward
{
roller2++;
}
else if (Input.GetKey(KeyCode.Mouse2) && Input.GetAxis("Mouse ScrollWheel") < 0f ) // backwards
{
roller2--;
}
roller2=roller2;
}
}
That code works for me using the middle mouse button.
I would suggest refactoring to read Input.GetKey(KeyCode.Mouse2) into a temporary variable (likewise with Input.GetAxis(“Mouse ScrollWheel”)) so you make less duplicate function calls.
If this is specific to a certain kind of mouse then you could raise a bug report with the specific hardware details.
You could also try the input debugger in window, analysis section of the menu. Select / double click the mouse entry and the click back to the game window to direct input to the game. Clicking the middle button triggers the ‘middleButton’ state to change.
You could also experiment with the input system package which is more powerful and might be of interest:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/Workflow-Direct.html
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/api/UnityEngine.InputSystem.Mouse.html
thanks for the heads up about the mouse, i tried another one and it works fine, cant understand that, mouse brank looks like enospeak or similar on the sticker it is very small but wont work for this script for some reason