- Home /
Detect Input type by checking if ANY key on keyboardd/joypad is pressed
is there a way to dynamically change the image of a button showing which key to press based on input type (keyboard & mouse | controller), so that when a controller is used, the button shows the A button (say) and when either the mouse or keyboard is used it swaps to the keyboard button instead?
Answer by toddisarockstar · Aug 12, 2015 at 11:33 PM
var img1:Texture;//-----drag and drop a texture in the inspector here var img2:Texture;//-----drag and drop a texture in the inspector here var tex:Texture; tex=img1;
function OnGUI(){ GUI.DrawTexture(Rect(Screen.width*0.2,Screen.width*0.2,Screen.width*0.2,Screen.width*0.2), tex); }
function Update (){ if(Input.GetKeyDown("a")) {tex=img1;} if(Input.GetKeyDown("b")) {tex=img2;}
}
how would that work for a joystick? The point of the question is mainly detecting if the user is using a joystick or a mouse/keyboard kind of input. What I can't do is checking if ANY key on the keyboard or the joystick is pressed. I'll edit the title to make it clearer.
Your answer
Follow this Question
Related Questions
is possible press 2 buttons at the same time Mobile touch? 0 Answers
Gear VR Clicking on regular Unity buttons 0 Answers
Unity Input - Keep button pressed while key is pressed 0 Answers
Use Canvas Buttons as Input Axis 1 Answer
How to click on button that is behind transparent image in New UI? 2 Answers