Hey all, pulling my hair out over this one. I have searched and seen this same topic posted many, many times and tried many workarounds/solutions and none have worked. The more frustrating thing is that my scene is relatively simple, so there aren’t a whole lot of places where things could go wrong.
I have two gameObjects I’m working with here - the player, who’s only collider is a PlayerController, who has one child object that absolutely does not have any colliders on it. (I have checked and checked again, and even deleted the object), and a Door. The door has a single Box Collider on it that is set as a Trigger and no child objects.
Below is the script on the door. As you can see, am I even disabling and then destroying the door’s Collider after executing my script, but it STILL fires a second time. The Debug Log always returns the name of the door and the name of the player.
Please help. I’m going insane, lol.
// Move the player through rooms when he goes through doors.
void OnTriggerEnter (Collider other) {
if(other.gameObject == player) {
Debug.Log ("Trigger at "+gameObject.collider.name+"+"+other.name);
switch(doordirection){
case(DoorDirection.North):
roomController.ChangeRooms(roomController.currentPlayerLocX, roomController.currentPlayerLocY+1);
player.transform.position = new Vector3(0, 1.5f, -14f);
break;
case(DoorDirection.South):
roomController.ChangeRooms(roomController.currentPlayerLocX, roomController.currentPlayerLocY-1);
player.transform.position = new Vector3(0, 1.5f, 14f);
break;
case(DoorDirection.East):
roomController.ChangeRooms(roomController.currentPlayerLocX+1, roomController.currentPlayerLocY);
player.transform.position = new Vector3(-16.5f, 1.5f, 0);
break;
case(DoorDirection.West):
roomController.ChangeRooms(roomController.currentPlayerLocX-1, roomController.currentPlayerLocY);
player.transform.position = new Vector3(16.5f, 1.5f, 0);
break;
}
gameObject.collider.enabled = false;
Destroy(gameObject);
}