To define a class, simply create a new script file (e.g., my_class.gd). The name of the file should represents the name of the class. Create a new file called player.gd with the following content:

class_name Player

var health: int = 100
var name: String = "Unnamed"

func take_damage(amount: int):
    health -= amount
    if health <= 0:
        print("Player", name, "has died!")
Comments