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!
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 :)
This is C#
GameObject.Find("DoorObject").animation.play("Door");
???