I have a method that creates a room by instantiating a prefab, places it in a grid and the re-sizes the collider based on a room definition (location in grid, rotation, width and height).
Here is the method:
public void CreateRoom(RoomAction action)
{
GameObject roomGameObject = Instantiate(this.roomPrefab, Vector3.zero, action.RoomPrefab.transform.rotation) as GameObject;
roomGameObject.transform.parent = this.transform;
roomGameObject.transform.localPosition = new Vector3(action.MansionOffsetX, 0, -action.MansionOffsetY) * this.blockSize;
roomGameObject.transform.localPosition += new Vector3((action.Room.Width * this.blockSize) / 2, 0, -((action.Room.Height * this.blockSize) / 2));
BoxCollider roomCollider = roomGameObject.GetComponent<BoxCollider>();
roomCollider.isTrigger = true;
roomCollider.center = new Vector3(0, this.height / 2, 0);
roomCollider.size = new Vector3(action.Room.Width * this.blockSize, this.height, action.Room.Height * this.blockSize);
roomGameObject.transform.RotateAroundLocal(roomGameObject.transform.up, Mathf.Deg2Rad * -90 * action.Rotation);
}
The problem I'm having is that, while the room rotates correctly, but for some reason, the collider isn't rotating with the game object.
Here is a screenshot:
Any idea on what am I doing wrong?