Posted July 12, 2025 by Rokanhellhound1
While working on implementing audio feedback for door interactions in our level, I ran into an issue using a switch function to trigger different sounds for opening and closing events. The idea was simple: when a door opened, it would play an "open" sound cue, and when it closed, a different "close" sound cue would trigger. However, the switch statement wasnβt working as expected. No sound played at all, or worse—both sounds would sometimes fire at once regardless of the doorβs state.
This became a user experience issue because audio cues are crucial for feedback and immersion. Without the proper sound playing at the right time, the interaction felt broken or unresponsive, which pulled players out of the gameplay experience. Fixing this was important for delivering a polished and professional feel to the game.
After testing and debugging, I found that the issue stemmed from how I was using the switch function. I was trying to pass in a Boolean value (true for open, false for closed) into a switch statement, which doesnβt work properly because switch cases are better suited for enumerated or integer values, not Booleans.
To fix it, I replaced the switch with a simple if/else conditional check. If the door was open, I triggered the βopenβ sound. If it wasnβt, I triggered the βcloseβ sound. I also made sure that the doorβs state was being updated correctly before the audio played, which helped avoid double-triggering.
This change made the interaction more reliable. Now, the right sound plays every time, and the player gets the correct feedback. Itβs a small detail, but it adds to the overall immersion and helps the player feel more connected to the environment and since I did it in a separate project now all I need to do is transfer it to the main project.