Skip to content

CelestialBody ​

概览 ​

字段值
KindUnit · 单位 Unit
Realmcommon

继承关系 ​

  • Unit(4 属性 / 25 函数 / 6 事件)
    • [CelestialBody](7 属性)

继承成员 ​

1 个来源 / 4 属性 / 25 函数 / 6 事件

天体类型用于在场景中布置太阳、月亮等天空发光体,支持同时存在多个实例。它通过颜色、亮度与角大小控制光球的视觉表现,并可指定贴图与朝向;开启跟随光照朝向后其方向会与场景光照保持一致,还可选择是否受雾效影响。

适用场景 ​

常用于为地图塑造天空氛围,例如创建一个发光天体作为太阳或月亮,再配合颜色与角大小表现不同的时段与天气观感。

使用要点 ​

使用 game:CreateUnit("CelestialBody", config) 或 World:CreateUnit("CelestialBody", config) 创建实例,创建时可在配置中传入 Color、Brightness、AngularSize 与 Texture。创建后直接读写实例上的 Color、Brightness、AngularSize、Texture、Orientation、FollowLightOrientation、AffectedByFog 等属性来调整表现。

注意事项 ​

该类型只能通过 CreateUnit 创建,不能使用 CelestialBody.New;按照公开示例将实例挂载到 LightingService 后再调整外观。多个天体可同时存在;若外观没有按预期变化,检查光照和雾效相关设置。

代码示例 ​

创建并挂载天体 ​

lua
-- @runtime client
local lighting = game:GetService("LightingService")
local celestialBody = game:CreateUnit("CelestialBody", {
    Parent = lighting,
    Brightness = 1.0,
    FollowLightOrientation = true,
})
print("天体已挂载到光照节点:", celestialBody.Parent == lighting)

属性 (7) ​

Name类型默认值说明
ColorColorColor.New(255, 255, 255, 255)Color 类型属性,表示该天体的颜色。
BrightnessFloat1.0浮点属性,表示该天体的亮度。
AngularSizeFloat5.0浮点属性,表示该天体在天球上呈现的角大小。
TextureStringofficial://image/20003字符串属性,表示该天体所使用的贴图资源标识。
OrientationVector3[45, -45, 0]Vector3 类型属性,表示该天体的旋转。
FollowLightOrientationBooltrue布尔属性,表示该天体是否跟随光照朝向。
AffectedByFogBoolfalse布尔属性,控制该天体是否受场景雾效影响。

关联类型 ​