Do I have a Boolean that I want to set to true while Input.GetMouseButton(1) is true, but the second I click the LMB (using Input.GetMouseButtonDown(0) ) I want to set the Boolean to false. However, it seems like I can’t get any other input from the mouse while holding down the RMB. I’ve tried compound if statements (i.e. if (Input.GetMouseButton(0) && Input.GetMouseButtonDown(0) ) and nested statements (i.e.
if (Input.GetMouseButton(1)) { if (Input.GetMouseButtonDown(0)) { // do something... } }
) as well as testing for these conditions using Coroutines but nothing seems to work. Anybody know a solution?
It works.
// do something when RMB is held down and LMB is clicked
if (Input.GetMouseButton(1)) // RMB held down
if (Input.GetMouseButtonDown(0)) // LMB clicked
Debug.Log("Do something");
Even if you use a bool:
if (Input.GetMouseButton(1))
{
myBool = true;
if (Input.GetMouseButtonDown(0))
{
myBool = false;
}
}
Debug.Log("myBool is " + myBool);
the bool will be false for a frame when LMB is clicked, then the bool will go back to being true, because RMB is being held down.
You’re example (Input.GetMouseButton(0) && Input.GetMouseButtonDown(0) ) won’t work because it’s only checking the LMB.
Not sure where your problem lies.
A possible work around is to separate the tests for the mouse buttons into two different if statements (no nesting or compound statements). Have two boolean variables, one for the LMB, and the other for the RMB. Set each one true if the corresponding button is clicked (or held down), and set it false otherwise (if else statement). Then in a separate if statement check if your two variables are true, then do whatever you wanted to do.