- Home /
door opening
i have searched for this a lot but i can't find it. i am searching for a script where you can play an animation of a door opening then staying open and when pressing e on it again it closes(maybe some fancy sound). it would be helpfull for a lot of people. also, how would you do that in cinema 4d? what i have now is frame 1 to 50 opening animation 51 to 100 closing animation. do i need to put an idle animation in it?
thanks for every one who would like to help.
Did you try searching for "door"? http://answers.unity3d.com/questions/130623/door-animation-after-press-a-key.html
Answer by Berenger · Feb 17, 2012 at 08:13 PM
You don't need the closing animation, unless it's different, you can play the opening backward. But you need to know the current state (openned, closed, moving)
Answer by tomekkie2 · Feb 25, 2012 at 02:00 PM
You don't need to use any frame animation at all. You can easily script the animatior instead.
If these are sliding doors you can use position
function Update() {
transform.position = Vector3(Mathf.SmoothStep(minimum, maximum, Time.time), 0, 0);
}
If hinged
just use transform.eulerAngles.y
Answer by deadshot · Oct 20, 2014 at 10:17 AM
using UnityEngine; using System.Collections;
public class door: MonoBehaviour { private int lastindex; public void play() { if(!animation.isPlaying) { if(lastindex==0) { animation.Play("RFdoor"); lastindex=1; } else { animation.Play("RFdoorclose"); lastindex=0; } } }
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
this is for playing the right animation.