Is there a way to slow down what's executed inside of Update()?
I'm a beginner to Unity so I may be going about this completely wrong. I have a button that when clicked it will add 1 to my score count. I also wanted to have this button add 1 to my score count every second while the button is held down. I have this somewhat working by using event triggers on my button (OnPointerDown and OnPointerUp), but when the button is held it adds the score too fast. Searching for answers has led me to Time.deltaTime, but I'm not sure how it could be implemented (or even if it should be) in this manner. Maybe I need to create a new function rather than calling Clicked() in Update()? Any help is very much appreciated!
public int score = 0;
public int baseScorePerClick = 1;
public bool touched;
public void Update()
{
if (touched) Clicked();
}
public void Clicked()
{
score += baseScorePerClick;
}
public void OnPointerDown()
{
touched = true;
}
public void OnPointerUp()
{
touched = false;
}
Answer by ChrisK007 · Apr 28, 2017 at 06:48 PM
I'm fairly new too, but I believe invokerepeating will be the solution.
You can set it going on the button down, and cancel it on button up, and it repeats at a frequency you set when you call it
Hey, that did just the trick. I just added InvokeRepeating to my OnPointerDown() function and a CancelInvoke on my OnPointerUp(). Thanks so much!
Your answer
Follow this Question
Related Questions
Play mode working differently on different computers 0 Answers
How to get 60 Frames per second in iOS? 0 Answers
Slow Motion Issues! 1 Answer
Time.deltatime not working. 1 Answer
time.deltaTime is not updating to give me an elapsed time 1 Answer