I think the code could be greatly simplified if delegates were used. you simply have two events for the switches and the gate subscribes to them (in case you want 2 switches). if not with a single switch it would be enough to do both functions of opening and closing. Eitherway great explanation and quite detailed, keep it up! 💪
Yes that would also be a way to do it. 🙂 So instead of having the scripts talk to one another directly, we could just subscribe the methods to a “open” and “close” event. And simply call those two. The problem however is when you start having 6 sets of doors with switches, since calling the event would trigger all the subscriptions. Or am I missing something? 🙂
@@Dani_Krossing yeah you are right, but all depends on the kind of game we are developing, if you only have few doors per level for example then it wouldnt matter, also with this method you would have to set manually all doors and that could lead to null references later. Both are good aproaches it just depends on what are we aiming for.
hey, i don't really know if you ever read this but i'd like to know since i watched your php tutorials if there is some way you could exclude specific names from registration except registering them
Hmm, I've watched this video several times in a row now. It seems my code is the same as yours but I can only use the button to close the door and only if the ''Is Door Open" button is klicked in on the door script. How come it doesn't work otherwise?
Neverm mind i just figured out i had a empty gameobject as the object that holds the switch behaviour i just put it on my switch head the red thignie and now it works thanks
Could we just use animation inside unity engine for door up and down ,and play that animation whan player enters a trigger or colide whatever ?i think that would be much easyer?btw nice video keep it up!
Yes that is also a valid way of doing it. 🙂 There are always multiple solutions to the same issue, and it’s just about which is more appropriate to the situation.