Wrong timing on animation + sprite flip;

I need to set an animation of flipping in a 2D game on Unity. How is the best way to do this?

I’m trying something like this pseudo code:

void FixedUpdate(){
if(lastSide!=currentSide)
flip();
}

void flip() {
if(lastSide == 1) // if is facing right
animator.SetTrigger(“flipToLeft”);

else if(lastSide == -1) //if is facing left
animator.SetTrigger(“flipToRight”);

this.player.transform.localScale = new Vector3(lastSide*-1,1f,1f);
}

Check out this thread for how you can post code nicely on the forums: Using code tags properly

Is your code working?
Does ‘lastSide’ get set somewhere else that isn’t shown?

I would suggest that you execute ‘Flip()’ when it’s needed, rather than polling in FixedUpdate().
I would suggest that you capitalize your method named ‘Flip’ (it’s not broken as-is, it’s just common).