Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

GDScript

继承: Script < Resource < RefCounted < Object

用 GDScript 编程语言实现的脚本。

描述

用 GDScript 编程语言实现的脚本,使用 .gd 扩展名保存。该脚本扩展了将其实例化的所有对象的功能。

调用 new 会创建该脚本的全新实例。如果现有对象的类与该脚本的基类相匹配,那么 Object.set_script 就能够扩展该对象。

如果你想要查看 GDScript 的内置函数,请移步 @GDScript

教程

方法

Variant

new ( ... ) vararg


方法说明

Variant new ( ... ) vararg

返回该脚本的一个新实例化对象。

举例:

var MyClass = load("myclass.gd")
var instance = MyClass.new()
assert(instance.get_script() == MyClass)