- Home /
Only updating once during left mouse button being held down.
I'm trying to detect when left click is held down on every frame, it should check to see if it still being held. I've put it in 'function Update' but it only shows up once even when held down. I want it to continuously detect it until released.
Code:
function Update () {
if (Input.GetMouseButton(0))
{
IncreasePowerBar();
}
}
function IncreasePowerBar()
{
Debug.Log("fire button");
}
Currently the Log only shows once when the LMB is held down, and doesnt even show a second time even if I release and re-click
Thanks in advance
Answer by AlucardJay · Nov 27, 2012 at 03:55 PM
Do you have your console collapsed?
In the Console window, make sure the tab Collapse is off !
http://docs.unity3d.com/Documentation/Manual/Console.html
When Collapse is enabled, identical messages will only be shown once.
It catches a few people !
No worries, just added more info, but glad it fixed the problem =]
Answer by CarlLydon · Apr 06, 2014 at 06:33 AM
In the manual it says:
Description Returns true during the frame the user pressed the given mouse button.
That means it will only trigger once, when you click. To do continuous stuff based on the mouse being up or down, you will need to toggle a variable when you click down, and toggle it again when you click up.
Answer by Landern · Nov 27, 2012 at 03:42 PM
Input.GetMouseButtonDown documentation.
function Update () {
if (Input.GetMouseButtonDown(0))
{
IncreasePowerBar();
}
}
function IncreasePowerBar()
{
Debug.Log("fire button");
}
Add a Debug.Log("$$anonymous$$ouse Button 0 Down") into the updates if block, if by clicking and holding and repeating, do you get the log message?
The Debug.Log does detect the mouse button being clicked, but i only comes up once. When i click multiple times it does nothing.
Your answer
Follow this Question
Related Questions
Converting button to mouse click 1 Answer
Unity doesn't recognize mouse clicks, C# 1 Answer
Click Sound 1 Answer
Mouse-click movement 0 Answers
Change Camera on (Right) Mouse Click 1 Answer