How to switch animation layers?

I have created 2 buttons where i want one to use the base layer with a default weight of 1 and when the other button is pressed the other layer should go to a weight of 1 which will override the base layer’s weight. i achieved this by using animator.setlayerweight (1,1) but now i have no way of telling my script to keep the second layers weight at 1 when the player restarts the game. i have tried writing within my restart function

if (animator.setlayerweight (1,1) )
animator.setlayerweight (1,1);

but as expected it wont work. how can i tell my restart function to keep the layer weight at 1 if it is already 1?
im new to programming and any help or pointers would really help me out, thanks.

Is there a chance that simply, you need to do this in OnEnable? Hope it helps…

did you mean if(animator.GetLayerWeight(1)) ?

1 Like