I am trying to make a room generator and i can't figure out how to fix this problem.
Main Node:
`public Vector2 right = new Vector2(464,0);
public Vector2 left = new Vector2(-464,0);
public Vector2 up = new Vector2(0,-256);
public Vector2 down = new Vector2(0,256);
public PackedScene room1 = ResourceLoader.Load<PackedScene>("res://Scenes/room_1.tscn");
public PackedScene room2 = ResourceLoader.Load<PackedScene>("res://Scenes/room_2.tscn");
public override void _Ready()
{
for (int i = 0; i < 4; i++)
{
var room = GD.Randi() % 2 + 1;
var roomInstance = room1.Instantiate<Node2D>();
if (room == 1)
{
var direction = GD.Randi() % 4 + 1;
if (direction == 1)
{
roomInstance.Position = right;
}
else if (direction == 2)
{
roomInstance.Position = left;
}
else if (direction == 3)
{
roomInstance.Position = up;
}
else if (direction == 4)
{
roomInstance.Position = down;
}
rooms.AddChild(roomInstance);
}
else if (room == 2)
{
var direction = GD.Randi() % 4 + 1;
var roomInstance2 = room2.Instantiate<Node2D>();
if (direction == 1)
{
roomInstance2.Position = right;
}
else if (direction == 2)
{
roomInstance2.Position = left;
}
else if (direction == 3)
{
roomInstance2.Position = up;
}
else if (direction == 4)
{
roomInstance2.Position = down;
}
rooms.AddChild(roomInstance2);
}
}
}`