- Home /
Trying to open door but not close the door aswell!!!
Hello I have just started coding about 2 days ago so it is quite simple but I am trying to open a door with the button "E" but I also want it, so that if I pressed the button "E" again it would not restart the animation. My animation is the door only opening not closing. This is my code at the moment. The error message on unity is "It is not possible to invoke an expression of type 'UnityEngine.Animation'." Thank you any help will be good.
Answer by xt-xylophone · Mar 25, 2013 at 11:19 PM
You could simplify it massively by having a boolean variable called 'isOpen' or something that starts as false and changes to true once opened.
Then in your update before anything else you can check if the door 'isOpen' and then just return so the function does nothing once the door is open :)
And you may wanna change that 4 on line 20 to $$anonymous$$axDistance if you hadn't noticed :D
Answer by ExpiredIndexCard · Mar 25, 2013 at 11:22 PM
http://docs.unity3d.com/Documentation/ScriptReference/Animation.Play.html You have to use animation.play to play an animation. You should also check out these for some more helpful things about playing an animation in Unity. http://docs.unity3d.com/Documentation/ScriptReference/Animation.html I suggest you go through them. That's how you learn and how you get better. :D Also, one more thing. Since you just started coding 2 days ago, you should look at the new tutorials Unity has made. They are awesome and they have beginner scripting tutorials. Here's the link: http://unity3d.com/learn/tutorials/modules