Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D
- @export var playerHealth : int = 100 #set this in the max value of progress bar
- var healthBar : ProgressBar
- var healthLabel : Label
- func _ready():
- healthBar = $HealthBar
- healthBar.value = playerHealth
- healthLabel = $HealthBar/HealthLabel
- healthLabel.text = str(playerHealth)
- #testing it works
- func _input(event):
- if event is InputEventKey and event.keycode == KEY_E:
- if event.pressed:
- playerHealth -= 10
- #stop player health going below 0
- if playerHealth <0:
- playerHealth = 0
- healthBar.value = playerHealth
- healthLabel.text = str(playerHealth)
- print ("Took 10 damage. Current Health: " + str(playerHealth))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement