//Called when the Door Collider has it's CollisionStay2D triggered. //Called whenever any object is touching the door. public void CollisionStay(Collision2D other) { if (door == null) { return; } // Need to check if the player is going towards the door. if (other.gameObject.GetComponent <Player>() && door.state == Door.DoorState.locked) { GameObject player = other.gameObject; bool correctKey = player.GetComponent <PlayerInventory>(). KeyInInventory(door.color); Cardinal4.Direction playerDirection = Cardinal4.Vector2ToDirection(player.GetComponent <Player>().GetPlayerDirectionVector()); bool playerGoingTowardsDoor = (playerDirection == direction); if (currentUnlockDelay <= 0 && playerGoingTowardsDoor && correctKey) { door.ChangeState(Door.DoorState.open); } else if (playerGoingTowardsDoor && correctKey) { currentUnlockDelay -= 1 * Time.deltaTime; } else { currentUnlockDelay = unlockDelay; } } }
private void DisplayDoor(Door door) { Room nextRoom = door.GetNextRoom(room); Vector2 vectorBetweenRooms = nextRoom.roomCoordinate.GetVector2() - room.roomCoordinate.GetVector2(); Cardinal4.Direction direction = Cardinal4.Vector2ToDirection(vectorBetweenRooms); doors[(int)direction].DisplayDoor(); }
private void GenerateDoor(Door door) { Room nextRoom = door.GetNextRoom(room); Vector2 vectorBetweenRooms = nextRoom.roomCoordinate.GetVector2() - room.roomCoordinate.GetVector2(); Cardinal4.Direction direction = Cardinal4.Vector2ToDirection(vectorBetweenRooms); DoorDisplay doorDisplay = Array.Find(doorDisplays, element => element.direction == direction); doorDisplay.door = door; door.doorDisplay = doorDisplay; }