[已解决]Godot - get_node:未找到节点 - GDScript

时间:2021-03-31 11:56:29

标签: nodes godot gdscript

请帮忙!当我为游戏的标题页运行代码时,我不断收到此错误消息!我对戈多很陌生。这是场景树:

Image

TitleScreen - 控制节点

- ColorRect - ColorRect Node
- Menu - VBoxContainer Node
    - Label - Label Node
    - Buttons - VBoxContainer Node
        - PlayButton - Button Node
        - QuitButton - Button Node
- Fade - ColorRect

这是连接到 PlayButton 和 QuitButton 的 GDScript 代码:

extends Button

export(String) var scene_to_load
export(bool) var quit

func _ready():
    for button in $Menu/Buttons.get_children():
        button.connect("pressed", self, "_on_button_pressed", [button.scene_to_load])

func _on_button_pressed():
    get_tree().change_scene(scene_to_load)

当我运行上述场景时,我得到:

get_node:未找到节点:菜单/按钮

任何帮助将不胜感激:)

感谢您帮助解决我的问题! My Title Screen After being fixed :)

我的游戏 Game

1 个答案:

答案 0 :(得分:0)

您说您已将 GDScript 代码连接到每个 Button,但看起来您应该将脚本连接到 TitleScreen,因为 $Menu 是 {{ 1}} 而不是 TitleScreen

您还需要将脚本修复为 Button 而不是当前的 extend Control

编辑

老实说,如果您只想通过按下按钮加载特定场景而没有其他任何事情,您可以直接从按钮更改场景 - 这只是一个脚本更改

extend Button
相关问题