Advertisement
metalx1000

Godot ProgressBar Color Change

Feb 9th, 2024
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Sprite2D
  2.  
  3. var health = 100.0
  4.  
  5. # Called when the node enters the scene tree for the first time.
  6. func _ready():
  7.     pass # Replace with function body.
  8.  
  9.  
  10. # Called every frame. 'delta' is the elapsed time since the previous frame.
  11. func _process(delta):
  12.     position = get_global_mouse_position()
  13.     health_update()
  14.    
  15. func health_update():
  16.     health -= .1
  17.     $ProgressBar.value = health
  18.     if health < 20:
  19.         $ProgressBar.get("theme_override_styles/fill").bg_color = Color.RED
  20.     elif health < 50:
  21.         $ProgressBar.get("theme_override_styles/fill").bg_color =Color.ORANGE
  22.     elif health < 80:
  23.         $ProgressBar.get("theme_override_styles/fill").bg_color = Color.YELLOW
  24.     else:
  25.         $ProgressBar.get("theme_override_styles/fill").bg_color = Color.GREEN
  26.    
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement