- Home /
Attack based on timer
I'm working on an attack system and wondering what the most efficient way of doing it would be. As the attack button is pressed, a counter is to start from 0.00, that goes up to 1.00, and then back down to 0.00. A UI bar shows the progress as it rises and falls, and if the attack button is pressed again during that progress, it stops and returns that float value. Any help appreciated, thanks :)
So the easiest solution for it is to use a linear interpolation of a time value, counting from 0 to 2 sec or something : if (presentTimevalue <= 1f) { image. Fillamount = (1+((0-1)/(0-1))*(presentTimevalue-2));} if (presentTimevalue > 1f) { image. Fillamount = (0+((1-0)/(1-2))*(presentTimevalue-2));}
that should do it!
Answer by BenWiller1989 · Sep 04, 2020 at 06:09 PM
If you use animations on it, you could use animation events for a perfect precision. But since I don't know, what type of game, its hard to say.
I just really need to know how I can start a counter that goes up to 1 and then back to 0, the rest I can do on my own - any ideas?
Y... Yes..., make a coroutine if you need seconds, since one second $$anonymous$$us one makes counted two,... So yield return new waitforseconds(1f) ; I don't know, why you need one and back but wathever you need. What counter do you mean? 1 to 10, every second or variable, every millisecond? That would be nice to know. Do you know how coroutine work?
yeah I know the basics of coroutines, not much though - since it's tied to the visual of a bar filling up and then depleting I thought it'd be better if it went from 0, to 1, then to 0 again. I'm using a UI image to display the bar on-screen, and the "fill" float value goes from 0 to 1
Your answer
Follow this Question
Related Questions
Attack speed 1 Answer
Cannot convert 'String' to 'float (but im actualy converting a float to a string) 2 Answers
Timer variable set to zero 2 Answers
cant change variable from a method? timer stays at 0! 1 Answer
Start timer with trigger 1 Answer