- Home /
Other : Asking for Scripts
How do I make A script to open 1 sliding door and another to open 2 sliding doors?
Hi all, Im not very good at scripting, in fact i know pretty much nothing and I am trying to learn as I go, I am making a game in unity and I have sliding doors, barns, one has 1 sliding door and the other has 2 sliding doors, in opposite directions. I am using Javascript. And I am stumped as to how to open them without using animations. thanks
You can use the same script if all it does is open every linked door. In one case you'd only link one door, whereas in the second you might link two or three doors.
Ex:
public Door[] door;
public void OpenDoors()
{
foreach (Door door in doors)
door.Open();
}
An excellent way to open doors or make new ones ->
["Open, says-uh-me"] (untested code)
Lo0Nuhti$$anonymous$$ i cant see anything in that page you linked, none of the comments mention anything about doors that i can see.
iwaldrop how would i use that code? i assume i need to create a cube with 'is trigger' and uncheck the mesh render, but how would i then get the door(s) to move, I forgot to mention earlier that i would like to use a keypress "f" to open the doors.
thanks for any help i can get
What is sounds like you need is a game object with a Sphere Collider on it that is setup to be a trigger, a script that will let the user know that they can hit the 'f' key to open the door, and a script that listens for the 'f' key being pressed (while the user is in the collider) which would then send a message to another scirpt that would run the above code. This would all exist on one game object in keeping with the Component Object $$anonymous$$odel.
Something like this:
GameObject SphereCollider Context$$anonymous$$essage $$anonymous$$eyListener DoorActuator
I would attach something like this to the door frame. Then I'd make a script called 'Door' (as I hinted at above) and link that into the DoorActuator script. When the user hits 'f' the $$anonymous$$eyListener would send a message to the DoorActuator calling the 'OpenDoor' method. If you want the door to automatically close after the player leaves the zone then you'd probably want a programmable value for the length of time that the door should stay open after the player leaves the trigger.
Remember to think of each job as a discrete task (a behaviour) that can be added onto any game object that you want.
Let me know if you have any more implementation questions, and I'll be happy to help.
iwaldrop, thanks, i can understand what you are saying, but i have no idea hove to write that code or anything, would you have a link to somewhere that could show me how to write, like something explaining why and how i use what i have to use. I have no experience with doing code.
Answer by Komak57 · Mar 30, 2014 at 11:00 AM
Door should contain a start, and open position which you will lerp/slerp between upon openning or closing. The alternative, is to create an animator for the door to automatically open/close when the value is set. I have door scripts that slerp open when in range, a rigidbody door that opens when pushed, and a chest that opens when [E] is clicked when looked at based on animations. I got what you need.
$$anonymous$$omak57 as i say i have no experience with script, i have no idea even how to start, i can open monodevelop and paste in someone elses script but no idea how to do my own yet
Follow this Question
Related Questions
How to make a double sliding door? 1 Answer
[Duplicated Question] Opening multiple doors 0 Answers
open a animated door 3 Answers
Private and public variables 2 Answers
How to Open a Door between two characters at the same time (singleplayer) 0 Answers