Hai I'm trying to make a level selector I need help in making buttons for it.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sheggif

I made a “parent scene” that I make inherited scenes from. Its a button with a picture and text with a color rect. I made code were it has a variable made into a string called scene_to_load and a variable that lockes and unlocks the level called unlocked. I made it so that if its lock(unlocked = false) then darken it with a color rect. It recieves a signal when the button is pressed and if its unlocked(unlocked = false) then it gets_tree whaterver that function is (if you can teach me about it then pls) and changes the scene into the scene_to_load variable/string. Here is the code if you need to see:

extends Button

export(String) var scene_to_load
export var unlocked = false

func _physics_process(delta):
if !unlocked:
$ColorRect.color = Color(0,0,0,0.2)

func _on_Button_pressed():
if unlocked:
get_tree().change_scene(scene_to_load)

:bust_in_silhouette: Reply From: exuin

I wasn’t sure what your actual question was, so I’ll just point out some things.

So first off, there’s a page in the official documentation on the SceneTree which explains it better than I ever could.

Second, there’s no need to set the color of the ColorRect every frame. You can just have it set to the locked color as default, and then change it when it’s unlocked. Also, buttons have a disabledproperty which you could use instead of a ColorRect. You can access the button’s pressed method directly with _pressed.