How to trigger an Animator Trigger through scripts (dependent on bool)

I’m making a point and click puzzle game and right now I’m working on a demo to get the mechanics working. I have 2 animations for a little cabinet, an open animation and a close animation. I’ve used the animator window to setup a system and I have triggers set up to trigger the animations (screenshot below). I’m working on a script to trigger the animations when you click the cabinet. Basically, if the cabinet is open and you click it, play the close animation. if the cabinet is closed and you click it, play the open animation. Click detection aside, how should I go about doing this? I’ve looked at a bunch of different tutorials but nothing seems to be working.

Here’s the animator window. demoAnim is the open animation and demoAnim2 is the close animation. Trigger “open” is between idle and demoAnim. Trigger “close” is between demoAnim and demoAnim2. They both work, I just need to be able to trigger them with a script.

@PotatoCode

Make a public animator in your script

public Animator animatorName;

Then to set the bool you use:

animatorName.setBool("nameOfTheBool", true);

I’m pretty sure you can use only one bool and play the opening animation when it’s true and closing animation when it’s false, but it’s gonna work either way :slight_smile: