Hi All,
I have a project and can only get one door to work. Here is the code that works:
private var clipLength = 0.00;
private var moving = false;
private var open = false;
private var originalPosition : Vector3;
private var originalRotation : Quaternion;
function Start()
{
animation.Stop();
animation[“open”].wrapMode = WrapMode.PingPong;
clipLength = animation[“open”].clip.length;
originalPosition = transform.localPosition;
originalRotation = transform.localRotation;
}
function OnMouseDown()
{
if(!moving)
{
if(open)
{
Close();
}
else
{
Open();
}
}
}
function Open()
{
moving = true;
animation[“open”].enabled = true;
yield WaitForSeconds(clipLength);
animation[“open”].enabled = false;
moving = false;
open = true;
}
function Close ()
{
moving = true;
animation[“open”].enabled = true;
yield WaitForSeconds(clipLength - Time.deltaTime);
animation[“open”].normalizedTime = 0;
animation[“open”].enabled = false;
moving = false;
transform.localPosition = originalPosition;
transform.localRotation = originalRotation;
open = false;
}
“open” is the name of the animation I am using. When I try to reuse the code and change the name “open” to say “doorflyout” it still only works for my original door. Is there a better way to toggle an animation? I built the animation in Unity.
Thanks!