25 lines
757 B
C#
25 lines
757 B
C#
using Godot;
|
|
|
|
namespace Tutorial1.Scripts;
|
|
|
|
public partial class Button : Godot.Button {
|
|
private RandomNumberGenerator random = new();
|
|
private PackedScene packedScene;
|
|
public override void _Ready() {
|
|
Pressed += OnPressed;
|
|
packedScene = GD.Load<PackedScene>("res://Character.tscn");
|
|
}
|
|
|
|
private void OnPressed() {
|
|
Node character = packedScene.Instantiate();
|
|
AddChild(character);
|
|
|
|
Sprite2D sprite2D = character.GetChild<Sprite2D>(0);
|
|
random.Randomize();
|
|
sprite2D.GlobalPosition = new(random.RandiRange(100,1000), random.RandiRange(100,1000));
|
|
|
|
GD.Print($"Add new character to position {sprite2D.GlobalPosition}.");
|
|
}
|
|
|
|
public override void _Process(double delta) { }
|
|
} |