How to open a lid and leave it open
Hello all, I want to open the lid of a box when it is clicked on and then want it to stay open. Currently this is happening: When I start the Game, the Lid opens (without being clicked on) and then jumps back to being closed. The animation only runs once. This is my code:
public class BoxLid : MonoBehaviour
{
private Animator anim;
void OnMouseDown()
{
anim = GetComponent<Animator>();
anim.SetTrigger("LidOpen");
}
}
I have no idea on how to leave the lid open and also do not know why the animation runs as soon as the game starts instead of when it is clicked on. Script is attached to the lid.
Any help would be lovely! Cheers!
What does your animator look like? you should have the default state of the lid in a closed position - no animation. Then a transition to the opening lid node with the condition like you have "LidOpen". You should have a third node with the box in the lid open position - also No animation and have a transition from the opening animation go to this third state of being open "Exit Time". Sounds like you have the box lid animation set as the default? You could also just have 2 states. Box open and box closed. Box open the default. And the animation of it opening simply a blend between the two states on "LidOpen". $$anonymous$$aybe even change the condition from a trigger to a bool. anim.SetTrigger("LidOpen", true) or anim.SetTrigger("LidOpen", false) then you could just bounce back and forth between blending the two states ( open and closed)
Your answer
![](https://koobas.hobune.stream/wayback/20220612233646im_/https://answers.unity.com/themes/thub/images/avi.jpg)