void Update()
{
if (Input.GetButtonDown(“Fire1”));
Debug.Log(“mouse pressed”);
}
In the code above, when i run it, i get the log message every frame instead of getting it when i press the mouse button (Fire1).
I don’t get why.
I’ve also tried Input.GetMouseButtonDown and had the same result.
You have a semicolon at the end of your if statement. That means “if condition, do nothing”
Then the next statement is the Debug.Log, which is NOT within the control scope of the if condition, so it executes every Update() call.
I highly recommend always using open/close brace even when the target statement is only a single one, since it helps guard against this sort of problem. You might also note that the Debug.Log statement is not indented, when clearly it should be if it were the target of the if conditional.
Also, you should consider using the code formatting tools for the forum, which will help your code be much more readable.
2 Likes
Thank you very much my friend.
About the indentation: I wrote it wrong here because i was in a hurry, but in the code everything is properly indented.
Thanks again.
1 Like
Hey there, glad you got it sorted. 
If you find yourself back on the forums to post, please take a moment to look at this page. It will show you how you can post code nicely here: Using code tags properly