- Home /
Unity Animation isn't working in built version
Hi guys
I have a totally absurd bug for you again. I have a door with two animations, one for opening and one for closing it. I'm using the script attached below. Like before, the system works flawlessly in the editor, but when I build the game, I can only open the door, but not close it with the animation. It just plays the opening animation again when I try to close it. I'm guessing that Unity doesn't export the closing animation, or I don't know. #pragma strict
var theDoor : GameObject;
private var drawGUI = false;
private var doorIsClosed = true;
var locked : boolean = false;
var DoorSoundOpen : AudioClip;
var DoorSoundClose : AudioClip;
var DoorLights : GameObject[];
var autoClose : boolean = true;
var autoOpen : boolean;
function Update ()
{
if (drawGUI == true && Input.GetKeyDown(KeyCode.E))
{
changeDoorState();
}
if(!locked)
{
for(var i =0; i < DoorLights.length; i++)
{
DoorLights[i].light.color = Color.green;
}
}else
{
for(var o =0; o < DoorLights.length; o++)
{
DoorLights[o].light.color = Color.red;
}
}
}
function OnTriggerEnter (theCollider : Collider)
{
if(locked == false)
{
if (theCollider.tag == "Player")
{
drawGUI = true;
if(autoOpen && doorIsClosed)
{
theDoor.animation.CrossFade("Open");
audio.PlayOneShot(DoorSoundOpen);
doorIsClosed = false;
}
}
}
}
function OnTriggerExit (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
drawGUI = false;
// if(!autoClose && !doorIsClosed)
// {
// theDoor.animation.CrossFade("Close");
// audio.PlayOneShot(DoorSoundClose);
// doorIsClosed = true;
// }
}
}
function OnGUI ()
{
if (drawGUI == true && !autoOpen && doorIsClosed)
{
GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Press E to open");
}else if(drawGUI == true && !autoClose && !doorIsClosed)
{
GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Press E to close");
}
}
function changeDoorState ()
{
if (doorIsClosed == true)
{
if(!autoOpen)
{
theDoor.animation.CrossFade("Open");
audio.PlayOneShot(DoorSoundOpen);
doorIsClosed = false;
}
if(autoClose)
{
yield WaitForSeconds(3);
theDoor.animation.CrossFade("Close");
audio.PlayOneShot(DoorSoundClose);
doorIsClosed = true;
}
}else
{
if(!autoClose)
{
theDoor.animation.CrossFade("Close");
audio.PlayOneShot(DoorSoundClose);
doorIsClosed = true;
}
}
}
Comment