|
Hi Unity users. I got a problem, i'm new on Unity 3D and i'm trying to use an animation for my door. Well, first of all, i don't know how to make a start or what i need, but now my question is. If my player is walking to a door that i made and i press a key ( by example 'D' ). The door should open with an animation and it stays open. Can someone help me please. I was searching for it, or something like that. But i found nothing. Please help someone. It's important.
(comments are locked)
|
|
There are a number of ways to accomplish what you're describing:
To get it to trigger (if, say you wanted to walk up to it and press a 'use' key), you'd check if your player was within range, then check if the key is pressed. Hope this helps! Additionally, try following along with some tutorials on the Unity website or watchign a few on youtube - it really helps. you said, "you'd check if your player was within range, then check if the key is pressed." How can i check that the player was within range. and how can i check the press key?
Jun 15 '11 at 10:29 PM
Ilias
Again, there are a number of way you could go about doing that. If you're serious about making things in unity, try searching here and on google for some tutorials. For now, you could:
You'll need the know-how to put that into action, though; so, again, tutorials/reading up on scripting.
Jun 15 '11 at 10:45 PM
Chris D
i'm using this JS for my door. function Update () { if (Input.GetKeyDown ("d")) animation.Play ("DoorHor"); } I created an animation for it and it works fine. When i press 'd', the door will open, but now i can open the door anywere in the scene. That's not the meaning of it. The door could only open when the player is standing close by the door and not anywere in the scene. How can i do this? PS: And it need to play once. and not everytime when you hit the 'd' key. Because the animation is playing again when i hit the 'd' key.
Jun 15 '11 at 11:41 PM
Ilias
(comments are locked)
|
|
I have seen the comment you put on the above answer by ChrisD, so I will answer those questions and provide some example code. First, in order to make sure that the player is near the door, you must have a Box configured so that it will cover the area that is considered "close" in your game. Then, you must go into the BoxCollider, and set the "Is Trigger" option. This will make it so that it does not act like a wall. Next, you do not want the box to be visible. So, go back to the Box GameObject, and remove the MeshRender component. Next, make a new script. I will use JavaScript, because that seems like what you are using. Unfortunately, I script mostly in C#, and have forgotten some of the syntax. This script needs to be attached to the Box object that you created at the beginning. The variable, I think I covered everything, but if there is something I forgot, please leave a comment. This is exactly were i was looking for, It works great!!!. But i found a little foul in your JS. It is 'boolean' and not 'bool'. ;) Maybe i can ask you a little question? I got also an animation to close the door. Is it possible to close the door when i press "d"? Only if the door is opened, then it can work. Edit: 19 juny 2011 - 00:14 AM
Jun 16 '11 at 10:38 PM
Ilias
sure! i will update the script. unfortunately i was out of town for the past two days and could not see the comments.
Jun 20 '11 at 03:59 AM
fireDude67
It's not working :-( When i want to close the door, it plays the DoorHor again.
Jun 22 '11 at 09:47 PM
Ilias
changed the script. apparently due to GameTime that would happen.
Jun 23 '11 at 02:52 AM
fireDude67
Not yet :(, But i think that it's enough. I changed my mind. I will the door stays open, and your help was awesome. you help me a lot.
Jun 23 '11 at 10:22 PM
Ilias
(comments are locked)
|
