Solved:
Instead of using PackedScene[ ], use Array<PackedScene>
[Export] public Array<PackedScene> BottomRooms;
[Export] public Array<PackedScene> TopRooms;
[Export] public Array<PackedScene> LeftRooms;
[Export] public Array<PackedScene> RightRooms;
[Export] public PackedScene ClosedRoom;
Trying to implement a Unity tutorial to Godot (Random Dungeon Generator) in C#
Help
Hi.
Trying to implement this tutorial to Godot: https://www.youtube.com/watch?v=qAf9axsyijY I have problems.
// ProceduralLevels.cs
// I've tried with Node2D
[Export] public PackedScene[] BottomRooms;
[Export] public PackedScene[] TopRooms;
[Export] public PackedScene[] LeftRooms;
[Export] public PackedScene[] RightRooms;
And
[Export(PropertyHint.Flags, "Top,Left,Right,Bottom")] public int Pos = 0;
ProceduralLevels levels;
uint randNum;
public bool spawned;
SceneTreeTween tween;
public override void _Ready()
{
GD.Randomize();
levels = GetTree().Root.FindNode("Levels", true, false).GetNode<ProceduralLevels>("Levels");
// levels = FindParent("Levels").GetNode<ProceduralLevels>("Levels");
Spawn();
}
public override void _Process(float delta)
{
DetectRooms();
}
public void Spawn()
{
if (!spawned)
{
GD.Print("Spawn");
if (Pos == 0)
{
randNum = GD.Randi() % (uint)levels.BottomRooms.Length;
GD.Print("Spawn::Bottom: ", randNum);
AddChild(levels.BottomRooms[randNum].Instance());
}
else if (Pos == 1)
{
randNum = GD.Randi() % (uint)levels.TopRooms.Length;
GD.Print("Spawn::Top: ", randNum);
AddChild(levels.TopRooms[randNum].Instance());
}
else if (Pos == 4)
{
randNum = GD.Randi() % (uint)levels.LeftRooms.Length;
GD.Print("Spawn::Left: ", randNum);
AddChild(levels.LeftRooms[randNum].Instance());
}
else if (Pos == 8)
{
randNum = GD.Randi() % (uint)levels.RightRooms.Length;
GD.Print("Spawn::Right: ", randNum);
AddChild(levels.RightRooms[randNum].Instance());
}
spawned = true;
}
}
void DetectRooms()
{
if (GetOverlappingAreas().Count == 0) return;
foreach (Area2D item in GetOverlappingAreas())
{
if (item.IsInGroup("SpawnPoint"))
{
QueueFree();
}
}
}
Also, in the Unity tutorial is using Invoke(); How to implement Invoke in Godot C#?
Thank you.