- Home /
Door Animation, Script Help Please!
I have a door animation, which has two elements in it as ive done it in 3Ds Max and one side opens to the left and the other opens to the right.
Can anyone be kind enough to show me some code that could work with this? Or at least point me in the right direction?
Animation Timing: 0-50 : Opening 51-60 : Open 61-100 : Closing
Also the animation is just named "Door" cheers in advance!
Answer by MC HALO · Dec 04, 2010 at 02:45 AM
Ok this script is done in JAVA i will give you two examples the first is if the player steps on something the door will open and the second is if the game runs the animation will play automatically :)
example 1:
function OnControllerColliderHit (hit : ControllerColliderHit){
if(hit.gameObject.tag == "Door") { // create a tag in unity and name it door and attach it to the door gameobject
animation.Play ("Door");
} }
the example above works if the player has a character controller around him, if the player hits the door it will then open up
example 2
This example is to make the door open automatically :
function Start () {
animation.Play("Door");
}
i just remembered another way this one is if you collide with something in the game world for example if you hit the bed the door will open
example 3:
function OnControllerColliderHit (hit : ControllerColliderHit){
if(hit.gameObject.tag == "bed") { // create a tag in unity and name it bed and attach it to the bed gameobject.
animation.Play ("Door");
// as soon as the player collides with the bed it will open the door :)
} }
now if the ideas worked for you let me know and if you are interested i can teach you a even better way of opening doors. i can show you how to use raycast to open doors this is a lot cooler because its like stuff you see in shopping centres when you walk next to a door it opens automatically and this is what raycast will do :))) hope these ideas helped :)
Hey, thanks thats a great help!
Yeah ive done a bit of research into RayCast and that idea would be great for my game! I will use example 3 for the time being as im being assessed on $$anonymous$$onday so i need some code to open my doors lol!
Thanks alot your a life saver (:
your most welcome i will make a tutorial on raycast and i will give you the link :)
Is there a chance you could show me the raycast tutorial because i'm trying to do the same as the previous guy only Im really new at setting up colliders, and knowing where to attach the script.
Answer by BerggreenDK · Dec 04, 2010 at 12:59 AM
This is C#
GameObject.Find("DoorObject").animation.play("Door");
???
Your answer
Follow this Question
Related Questions
How to attach Animation to other objects in script? 1 Answer
multiplying door problem!! 2 Answers
Attack Animation Trigger 1 Answer
Starship Doors / Hatches 2 Answers