add to list variable on player enter

Syed Suhaib Zubair 3 months ago in Other updated 3 months ago 6

I want to discuss a situation and need a solution. i am confused how to use list variables with gameobjects and bool values.

i have a building and some room doors are open and some doors are closed. i want to do that if  "on player enter" trigger the door is already open then close the door and if not then open the door. i add local variable of bool on each door with name "IsOpen". if player enter it change its value true to false or vice versa. but i want to make the list of doors and if i am near a door "IsOpen" bool condition works according to the GameObject.  hope you understand what i am trying to say.

how to Get the name of Door and open or close it accordingly.

Unity version:
Game Creator version:
Satisfaction mark by Syed Suhaib Zubair 3 months ago

I think I understand. You kind of answered yourself, but here it goes: To start, I would create an empty game object (let's call it "Door") and place it in the center of the scene. Add a component Trigger with "On Player Enter", a Local Variable with a Bool variable called "is-open" and a Box Collider set with "is Trigger" checkbox marked.

Now, inside this game object you'll need to place the 3D model with the animation of the door. I'll leave this up to you, but make sure everything is locally at (0,0,0) so you can move the Door empty game object you initially created to move the entire thing and place it where you want.

Now, on the Trigger you created, call a Condition and check if the variable (drag and drop the Door game object) "is-open" is true or false, and open/close it depending on the value.

You can also add another Trigger "On Player Exit" to close the door in case you want them automatically close when the player leaves the door zone.

Hy. i would like to ask one more thing that what to do if i want to open door opposite direction of my face. I mean if i am inside a room when i try to open the door it should rotate other side of my character. and same from outside the room.

Using your above suggestion i am only able to rotate the door in one direction only. How to store the previous position and rotation?


You could use two box colliders as Triggers (as Marti described) on each side of the door, each triggering a different animation.
Might also wanna use Transform/Rotate instead of an animation to make it more performant/easier.

but there is an issue. if i have a building and i have move than 100 doors and are of different types then how i  can use the same trigger and "Is-Open" bool variable for all. Is that possible to create bool variable and trigger once and then just use collider and get the door status open or closed and its name and use the central trigger to perform accordingly.

Otherwise according to (Marti) i need to create triggers and bool variable for each door and this is too much and time taking work.

Will you please suggest any solution for it.


You can just make a prefab of your Door with everything set up that you need and be able to just drop it into your scene as many times as you want.

I have a simple door that uses a bool for open/close condition and a rotation transform which is relative, so it doesn't break even if I rotate my door. Works pretty well, and I can just copy and paste it wherever I need a door. Here's my setup if it's helpful:

I got your point. Its mean if i have a different type of door then i have to create a prefab different with the given triggers. Thanx for the Solution.