(2D Project) I have a very basic set-up in which I have a Hallway with a door and a bunch of other objects. I have a player that starts on the left side of the hallway and only moves on the x-axis. The player has a Box Collider 2D and a Rigidbody 2D. He has a script that allows him to move and within the script I have a method called "CheckEnterDoor()", which, if the bool "main" is true, > if you press e, unloads the hallway and its objects and loads a secondary room. If you press e while in the secondary room, the opposite happens, secondary room gets unloaded, main hallway gets loaded (they become invisible, atleast, I am not sure what technically happens to them [SetActive(false)])
I call this method from within a different script which, instead of being attached to the player, is attached to the door. The door has a Collider2D which is set to "Is Trigger", so that you can pass through it and use it as more of an "area of interactivity", atleast thats the way I am trying to use it. It just has the basic setup so that the door script can access the player script and then within "OnTriggerStay2D", which, the way I understood it, is supposed to be some sort of a "while(in_Collider2D_area)", I try to make it possible to open the door.
but pressing e while inside of the door box only works SOMETIMES. Sometimes while I'm walking towards it I'll press e and it works. Sometimes I'll do that exact same thing and it doesn't. Sometimes I need to move around a bit within the massive box while spamming e to make it work. I can always get it to work, but it seems to be completely random as to WHEN it actually works. I have seen people have similar-ish issues with this in some 2015 post, the suggested solution was to use a Kinematic OR Dynamic Rigidbody 2D Body Type instead of a static one, because that could apparently cause issues. My Rigidbody2D was set to Dynamic by default and the only option within it that I changed was the gravity so that the player wouldn't just fall through the floor. Using the Kinematic Body Type did not resolve the problem either, though. Another fix I saw was to put the Rigidbody 2D to "Never Sleep" mode, which I did, but it again did not change anything. I might not have been able to find a proper answer to this because I am unsure how to actually formulate my question or describe the issue without making it overly specific.
**I have used Debug.Log("blabla"); and it has continously given out a ton of messages into the console, meaning the Program seems to fully realise that I AM inside of that Collider2D box, yet will not let me execute the code. I am now thinking it might be a code problem instead of a box-dragging or rigidbody settings problem.
This is my first time posting here and also my first time working with Unity, if I need to send the project or full source code or anything like that somehow please let me know and I will do it.