在 Godot 4 中的实例化对象中调用函数

问题描述 投票:0回答:0

下午好,我正在为我正在开发的游戏开发区块加载系统。 我来自 unity,所以我用 c# 编写所有代码。 我制作了一个块对象场景并成功加载并添加到场景中。 我遇到的问题一旦实例化,我就无法在块对象上调用函数

下面是创建块并尝试在其上调用函数的代码

        var chunkScene = ResourceLoader.Load<PackedScene>("res://Chunk.tscn");
        // Instantiate the chunk node
        var chunk = chunkScene.Instantiate();
        // Add the chunk to the scene
        AddChild(chunk);
        chunk.DoIt();/*<-- this is an example function that exists on the chunk object that i am trying to call*/

我已经确认块对象是正确的(在这种情况下,它是一个 Node3D 命名块,它附加了一个脚本,并定义了函数,但出现以下错误

'Node' does not contain a definition for 'DoIt' and no accessible extension method 'DoIt' accepting a first argument of type 'Node' could be found (are you missing a using directive or an assembly reference?)

这很奇怪,因为我希望类型是 Node3D 而不是节点,因为使用 print 获取实例化对象的详细信息会给我正确的类型和名称。

我对 Godot 很陌生,欢迎任何意见来澄清我在这里可能做错了什么。

我已经收集了生成对象的信息,尝试了几种不同的实例化方法,并确认没有其他节点存在。

c# instantiation godot
© www.soinside.com 2019 - 2024. All rights reserved.