- Home /
Help making an animated door (c#)
I am making a game that, when you click a door, the door opens. When you click again, the door closes.
But i could only make the door open. When i click again, it goes back to the ground and goes up again. I wanted it to close (or play the animation by reverse) :/
Help?
BTW here is the code im using:
using UnityEngine;
using System.Collections;
public class OpenDoorClick : MonoBehaviour {
void OnMouseDown()
{
gameObject.animation.wrapMode = WrapMode.Once;
gameObject.animation.Play();
}
}
Answer by Gjallanhorn · Oct 06, 2013 at 03:55 PM
simplest is to make another animation of the door closing, and play it:
bool doorOpened = false;
void OnMouseDown()
{
gameObject.animation.wrapMode = WrapMode.Once;
if(!doorOpened){
animation.Play("open");
doorOpened = true;
}else{
animation.Play("close");
doorOpened = false;
}
}
When i try to make another animation it says "can't have 2 animation components"
In the animation component, you have a array called animations, just change its value to 2, and add your other animation.
Or drop your new animation onto the current one, which will automatically increment it down. I've seen reports of some users only being able to increase their array to 5 manually though the number editor.
Ok i tried that and it worked, but if i click on the door really quickly the animations playback again and again really fast. How do i make it so you have to wait for the door to open to the other animation to play again??
BRU$$anonymous$$P BRU$$anonymous$$P BRU$$anonymous$$PIDY BRU$$anonymous$$P
Your answer
Follow this Question
Related Questions
Model stays at the end of my animation D:? 0 Answers
Animations aren't playing in reverse. 0 Answers
Reset and Play Animation using UI Buttons - Replay Button 0 Answers
Button to play animation in reverse 1 Answer
Destroy animation on completion 0 Answers