Here's a more complete example, where you can drag a HorizontalSilder
to set the value of the ProgressBar
and see the color change accordingly. Don't forget to connect the on_value_changed
signal of both controls to the below script.
extends CanvasLayer
onready var styleBox = $ProgressBar.get("custom_styles/fg")
func _ready():
$HSlider.value = 50
func _on_HSlider_value_changed(value):
$ProgressBar.value = value
func _on_ProgressBar_value_changed(value):
var r = range_lerp(value, 10, 100, 1, 0)
var g = range_lerp(value, 10, 100, 0, 1)
styleBox.bg_color = Color(r, g, 0)
That works with the script attached to the top-level of a scene tree that looks like this:
