Good Morning, I'm Maria, and I'd like to know how to animate in 2D the doors (open and closed) whit programming. Thank you for the help
Hey, I don't think you need the "Iddle" and "Open" bools in your animator. The door can either be opened or closed, so you only need the "Closed" bool. Set it to true when the door is closed, and false when the door is open. You can use OnMouseDown() to toggle between open and closed. Here is an example of what you could do: Code (CSharp): Animator animator; void Start() { animator = GetComponent<Animator>(); } void OnMouseDown() { if (animator.GetBool("Closed") == true) // If the door is closed... { animator.SetBool("Closed", false); // Open the door. } else // If it's not closed... { animator.SetBool("Closed", true); // Close the door. } } Just make sure that you have a "Box Collider 2D" component on your doors. Here is what your Animator Controller should look like: Good luck!
[QUOTE = "Mery87, publicación: 7494284, miembro: 3859124"] Gracias I mean what do you have to do to do that the animations solo work when I do click on the doors
Hey, That's my mistake, I forgot about the initial door state. You don't want the door to start animating right away, you want it to be closed at the start. First, make sure that "Loop Time" is unchecked for your animations; you only want them playing once. There are a few ways you could make the door closed at the start. One is to use an "Idle" state like you were doing before, but I think it would be much easier to add animator.Play("Closed", 0, 1f); to the Start method. So it would look like this: Code (CSharp): void Start() { animator = GetComponent<Animator>(); animator.Play("Closed", 0, 1f); } What this does is start the Closed animation 100% of the way through, so it starts finished. Because you don't have loop time, the door will be closed at the start, and then everything else will work normally. Hopefully that made sense, please let me know if you have any questions.
i think already it works in the animator but i need to know now is how to do the animations only works when you clicks in the doors
Hey, For this line animator.Play("Closed", 0, 1f);, you need to replace "Closed" with the name of your state. In your case it would be animator.Play("Puerta_Closed", 0, 1f);. You need to set the bools when you click on the doors through code. I already showed the code you could use for that earlier: