Godot Version
4.6
Question
Hello everyone
I try to make a UI scene similar to this one from Wargroove, and for that, I created scenes, including one, called “UnitRecruitOption” :
using System;
using Godot;
public partial class UnitRecruitOption : Container
{
private Button button;
private FakeUnit unit; // Name + stats + sprite
private int cost;
public event Action<FakeUnit> ChosenUnit; // When the unit is finally chosen. The higher up will know if expensive or not
// Called when the node enters the scene tree for the first time.
private static readonly string NodeScene = "res://GodotRes/UI/unit_recruit_option.tscn";
private bool DeployChoice = true;
public override void _Ready()
{
GD.Print("Instance UnitRecruitOption");
button = GetNode<Button>("UnitButton");
button.Pressed += CreateUnit; // Equivalent to connect
}
public override void _ExitTree()
{
button.Pressed -= CreateUnit; // Unsubscribes
}
/// <summary>
/// Broadcast for the entire game that a new unit must be created
/// </summary>
private void CreateUnit()
{
ChosenUnit?.Invoke(unit);
}
}
I use built-in C# events, as they are recommended instead of Godot signals when using C#
Is there a solution ? Thank you in advance
