Code timer to replace animator

I want to create a timer with code to replace the animator component, I will then display the frame of animation I want based on the state of my new timer

I was thinking about something like this:

public float animSpeed;

public float currentTime;
public float targetTimeToChangeFrame;

void Update()
{

if (currentTime>targetTimeToChangeFrame)
{
currentTime = 0;

ChangeFrame();
}

currentTime  = currentTime  + animSpeed * Time.deltaTime;
}

Is this method anywhere near best practices of an accurate way to manage time?

Is it similar to how the animator component manages time?

Thanks for the advice

PS: To answer any possible questions about why dont I just use the animator component, its unecessary overhead since I have come to the point where my game isnt making use of any of the animator states, transitions, and other features, and atm Im just lifting the values off the animator state info to run my own animation logic, and its very clumsy and unecessary to do so

I mean there’s many ways to do a timer. All that matters is: does it work?

do you think what I have is good or can you point me to a better way if not?

Thanks for the reply and help

Does it work or not? That’s all that matters.

1 Like

Best practices and $5 will get you a cup of coffee.

Again, does it work? Move onto the next problem.

If it has a problem, fix the problem.

Remember: one piece of code might work PERFECTLY in one context and HORRIBLY in another context, so posting that piece of code here in total isolation is not a productive use of time.