How to change the frame of the component srite mesh animation at runtime ?
Hello,
I have a problem, I use anima 2D and I want to change the frame of the sprite mesh animation at runtime in the script. For that, the animator must be disabled. So I'm doing this:
Animator anim;
void Awake()
{
anim = gameObject.GetComponent<Animator>();
}
private void Update()
{
//if the player picks up the pickaxe
changeSpriteLeftHand();
}
public void changeSpriteLeftHand()
{
int currentFrame = LeftHand.frame;
anim.enabled = false;
if (currentFrame != 3 && PickAxe && !Gloves)
{
currentFrame = 3;
LeftHand.frame = currentFrame;
}
if (currentFrame != 8 && !PickAxe && Gloves)
{
currentFrame = 8;
LeftHand.frame = currentFrame;
}
if (currentFrame != 10 && PickAxe && Gloves)
{
currentFrame = 10;
LeftHand.frame = currentFrame;
}
anim.enabled=true;
}
When the animator is reactivated it puts the frame back to default. BUT when I delete the line that reactivates the animator and I reactivate it manually by clicking on the inspector, it works and it keeps the modified frame.
Why it does not work in the code but it works by manually reactivating the animator?
Thanks for your help
Comment