I’ve recently started messing around with Unity on a simple game, but having trouble with the door script. I’m trying to follow a tut, but something went wrong, lol.
In my hierarchy I created an empty game object. I’ve added my door mesh to it, which has box collision. I wrote a script, and attached the mesh to the Object variable…
The script is here.
#pragma strict
var doorObj:GameObject;
var IsOpen = false;
function OnMouseDown(){
if (!this.IsOpen){
doorObj.animation.Play("DoorOpen");
this.IsOpen = true;
}else{
doorObj.animation.Play("DoorClose");
this.IsOpen = false;
}
}
function Start () {
}
function Update () {
}
I’ve double checked the names of my animations, and trimmed them right, so not sure what’s going on with this thing.
Thanks.
I just realized my box collider was invalid for this because it was added to the mesh and not the game object… Now the animation plays, but all weird… not sure if it fits this thread or not… The door goes several feet from the door frame, and then plays the animation…
Edit - The door animation plays fine on it’s on… When set to play automatically.
Something about the game object is messing with the animation as far as I can tell, but not sure what it is.
Hope someone can help 
Do u have your door as the child of an obj (eg) a house or building? If so the local pos may have something to do with it.
I found that using a hinge joint works better and more realistic than animation. Hinge joints have motors that can be scripted to work with triggers to create a nice door experience.
Hmm, local position. I’m not sure… I’m not good with the whole 3d world, scale, snapping, and all that. I just sorta model things, and hope they work, lol.
The door isn’t parented or child to anything else though… It’s just a thin rectangle image mapped with a door image, but it’s not a conventional door… a sliding sci-fi door…
I just made the animation in Maya. A simple one. set a key frame, nudged the door sideways, set a keyframe, nudged it sideways… Like that…
Thanks for the reply 
It would seem your most likely right though. After a few minutes with Google I found people having the same problem. The given solution was placing the animated object inside an empty parent object to play local position… How can I test that? Or is my empty game object with the script the same idea?
edit - I’m not sure how to parent things in Unity…
Thanks