Topic was automatically imported from the old Question2Answer platform.
Asked By
Geox2
I want to change to the next scene by clicking the label.
My code:
extends Label
var current_scene = null
func _ready():
pass
func _on_Start_gui_input(event):
pass
if (event is InputEventMouse && event.pressed && event.label_index == 1):
if get_tree().change_scene(“res://assets/Greetings.tscn”) != OK:
print(“An unexpected error occured when trying to switch to the Greetings scene”)
Sorry, what specifically is the issue with your code?
exuin | 2021-03-06 18:57
Well, i used this code to use the label to change my scene, but it doesn’t work when I pressed the label, so I need help on making it work.
As another option if you want to use a Label only, you can check if the mouse click is inside the Label area as follows:
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.button_index ==1 and event.is_pressed():
var mouse:Vector2=get_global_mouse_position()
var label: Label=get_tree().root.get_node("Node2D/MyLabel")
var rect:Rect2=Rect2(label.rect_position, label.rect_size * 2)
if rect.has_point(mouse):
print("Clicked Label. Change Scene here")
pass