- Home /
Input.GetKey(KeyCode.Mouse0) does not work if any other Buttons is pressed how can i get around this?
I have tried Input.GetButton("Fire1") as well and it still does not work if other buttons are pressed or held at the same time. I am trying to do trigger a shooting animation when i run but i can only get it to work while standing. it does not work even if i hold down an unrelated button that i don't use for anything. here's my code if it helps! And the Debug.Log messages only appears in the console if i am standing still and no other buttons are pressed or held while pressing or holding Mouse0. Oh and i want to be able to click anywhere on the screen not just on specific object! sorry for wall of text and thanks in advance!
public Animator MyAnimator;
void Start () {
MyAnimator = GameObject.Find("GunShotAnim").GetComponent<Animator> ();
}
void Update () {
if (Input.GetKey(KeyCode.Mouse0)) {
MyAnimator.SetBool ("BOOM", true);
Debug.Log ("ClickDown or held");
} else if (Input.GetKeyUp(KeyCode.Mouse0)) {
MyAnimator.SetBool ("BOOM", false);
Debug.Log ("clickUp");
}
}
This works on my computer ... I tried holding down keyboard buttons and mouse buttons and it works as expected in both cases. Does it make a difference if you remove the $$anonymous$$yAnimator stuff?
Nope it doesn't make any difference at all.. but i should maybe add that i am not using a real mouse, I am using my Laptops mouse-pad when trying it out. I think that might screw something up in the Input.. I'm going to buy a mouse and try that out. Thanks for your help and time!
I also tried it with my mouse-pad, that works too. Seems like something specific to your laptop ...
Answer by VPanom · Oct 04, 2016 at 09:31 PM
Hey everybody that follows this question and or have the same problem and stumbles upon this post! The issue seems to be in my computer. I connected a real mouse and everything works just fine now. I have previously used the mouse-pad. My laptop brand is an Asus X555L, If that helps anyone that is experiencing the same kind of issue! Happy coding, Best regards Victor!
Answer by AurimasBlazulionis · Oct 03, 2016 at 09:00 PM
You can also use Input.GetMouseButton. That should really work. If it does not, then it might be something wrong on your side. Also, if it does not, try it in build, sometimes some editor extensions block things.
Nope it doesn't make any difference at all.. but i should maybe add that i am not using a real mouse, I am using my Laptops mouse-pad when trying it out. I think that might screw something up in the Input.. I'm going to buy a mouse and try that out. Thanks for your help and time!
Your answer

Follow this Question
Related Questions
Differentiate left, right and both mouse inputs 0 Answers
Two buttons (Quads) are not working at a same time. 2 Answers
How to check which key i have pressed? 3 Answers
Raycast hit not detected on cube 1 Answer
Disable mouse input and cursor in game 2 Answers