- Home /
Action on mouse button up
My script is supposed to deactivate a variable every time the left mouse button goes up. For some reason, my script sometimes 'misses' running that part of the script when i let go of the left mouse button, and some times it works. I had it print a counter every time it ran that part of the script to be certain.
I have the script in the Update() function and have even tried the FixedUpdate().
In my game it is integral that the player have full control of the scene by holding down and letting go the left mouse button.
How can I write the script well enough to be certain that every time the left mouse button is held down and at a decided time let go that unity will not miss an event?
Thanks a Ton!
Answer by Eric5h5 · Feb 19, 2010 at 02:22 PM
Definitely don't use FixedUpdate, because it doesn't necessarily run every frame, and can miss events if they happen during a frame when FixedUpdate is not running. I've never seen an event missed if it's checked in Update.
I'm not even sure what FixedUpdate is for. From the description it says it's for physic interactions. In practice, I'm guessing it should be used just for NPC's and non-critical elements for saving processor cycles.
No, FixedUpdate is only for physics interactions, such as applying AddForce or suchlike. It should not be used for non-physics code, because while it might save CPU cycles when the framerate is high, it will use more CPU cycles when the framerate is low (below the fixed framerate), which is exactly the opposite of what you want. For code which should only run occasionally, use InvokeRepeating or other methods.
Your answer
Follow this Question
Related Questions
Frame dependant game. Using update vs fixed update. 3 Answers
How often does the internal physics calculation get called? 1 Answer
Is there an equivalent of Time.frameCount for physics updates? 1 Answer
Slow motion all but one - yet another round, hopefully the last 6 Answers
Fixed timestep... 1 Answer