0 votes

Guys, help out, I don't know how to rewrite this code in C#...

signal health_updated(health)
signal killed ()

export (float) var max_health = 100
onready var health = max_health



func kill():
pass



func _set_health(value):
var prev_health = health
health = clamp(value, 0, max_health)
health i= prev_health:
emit_signal("health_updated", health)
health == 0:
kill()
emit

I partially know how this miracle will look in C#, but it turns out crooked, can you recommend something?

Code by the way is not Mine, so do not scold :)

in Engine by (137 points)

1 Answer

0 votes
Best answer
   public class SampleNode: Node2D
{
    [Signal]
    public delegate void HealthUpdated(int health);

    [Signal]
    public delegate void Killed();

    [Export] public float MaxHealth = 100;
    public float Health;
    public override void _Ready()
    {
        Health = MaxHealth;
    }

    public void Kill()
    {

    }

    public void SetHealth(float value)
    {
        var prevHealth = Health;
        Health = Mathf.Clamp(value, 0, MaxHealth);
        EmitSignal(nameof(HealthUpdated),new[] {Health});
        Health = 0;
        Kill();
    }
}
by (44 points)
selected by

Thank you friend, helped out! I apologize for my stupidity...

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.