- Home /
GetMouseButtonUp, literally?
I'm trying to get this simple function to work as desired:
function Update()
{
if(Input.GetKeyDown("1") && Input.GetMouseButtonUp(0))
CallNext();
}
The thing is that I want it to work when I press 1 ONLY if I'm NOT holding down Mouse0 at the same time. This is to prevent bugs to occur.
Any ideas how I can achieve this?
Answer by Eric5h5 · Mar 15, 2014 at 03:34 AM
You don't mean when the button is up, you mean when it's not pressed. "ButtonUp" requires that it was pressed first.
if (Input.GetKeyDown(Keycode.Alpha1) && !Input.GetMouseButton(0))
Ah, thank you. If it just needed that "!", it could be solved without having someone to re$$anonymous$$d me if only Unity Documentation had a section specifically about these darn things ---> && ! == ||
That's just standard coding, not anything Unity-specific.
Your answer
Follow this Question
Related Questions
Collect Key and open door 2 Answers
Press 'e' key on object? (C#) 2 Answers
C# Capture Keypress 3 Answers
How does code licensing for Unity works? What happens when I post for evaluation / showcase? 1 Answer
Instantiate as child 3 Answers