Hi guys, any help would be greatly appriciated
I’m just trying to capture the time someone clicked something, but the variable just keeps incrementing
public float startTime;
public float clickedTime;
startTime = Time.time;
clickedTime = startTime;
Both of these are in the update section of the script but I think I need them both there. I just wanted clicked time to stop incrementing so I can use it for comparison.
Ideally, if startTime is 3 seconds, and the user clicks, I’d like to record clickedTime as 3 seconds and not increment, while startTime continues to increment.
Any thoughts?
I meant to say “non incrementing” variable in the title, not floating
Update gets called over and over while your game runs. So if you’re just setting clickedTime to the currentTime in update, it’s going to keep doing that over and over. You probably want to do this:
if(Input.GetButtonDown(“Fire”)) clickedTime = Time.time;
That way you only set clickedTime when the button is pushed, not over and over.
use an if block to check if the mouse is pressed and then set the clicked time to equal start time. Right now your variable is just incrementing each frame
EDIT: MakeShift beat me to it… but yes he is correct however i’d recommend using GetButtonUp