Below is a script to make a sliding door instead of a regular one suitable for sci fi levels and futuristic doors.
Unity sliding door with switch script.
All of your doors open because you re not actually checking whether or not the hit object from your raycast is actually the door object your script is holding a reference to.
This is a simple task for beginners to unity and programming with c.
Imtiaj touches on this briefly but string compares on game objects are a bad idea and does not limit yourself to one object as many game objects an have the same name.
In this tutorial i added a script to open the door when an fps player enters a trigger.
Slidingdoor cs make an empty gameobject and call it door drag and drop your door model into scene and rename it to body move the body object inside door add a collider preferably spherecollider to door object and make it much bigger then the.