當 Sky 對象放置在 Lighting 內時,會改變體驗天空的預設外觀。這個對象的 天空盒 由六個面組成,像是立方體。天空盒的旋轉可以通過 SkyboxOrientation 來變更。
除非您關閉 CelestialBodiesShown 屬性,否則天空盒的太陽、月亮和其他天體仍然可見。通過調整 StarCount 屬性,您可以改變夜空中出現多少顆星。
此對象也可以用作在 ViewportFrames 中的反射地圖,在此情況下,只使用 Sky 對象的六面體 Skybox[…] 屬性。詳情請見視窗框。
概要
屬性
設置太陽、月亮和星星是否會顯示。
使用此天空盒時,月亮的感知角度,以度為單位。
使用此天空盒時月亮的紋理。
天空後面的圖像的 URL 鏈接。
天空盒底部表面的資產ID。
天空盒的前表面資產ID。
天空盒左表面的資產ID。
天空盒的角度,以度為單位,並具有旋轉順序 Y 、 X 、 Z 。
天空盒右側的資產ID。
天空盒的頂部表面資產ID。
天空盒中顯示了多少星星。
使用此天空盒時,太陽的感知角度,以度為單位。
使用此天空盒時,太陽的紋理。
屬性
MoonTextureId
使用此天空盒時月亮的紋理。
SkyboxBk
天空後面的圖像的 URL 鏈接。
SkyboxDn
天空盒底部表面的資產ID。
SkyboxFt
天空盒的前表面資產ID。
SkyboxLf
天空盒左表面的資產ID。
SkyboxOrientation
變更天空盒表面的方向。這個屬性會在典型的 XYZ 順序中消耗 度值 的一部分 ,但旋轉會先在 Y 軸上應用 X ,然後 X ,然後 Z 以允許對複雜運動進行預測控制。
一個簡單的方法是在 Y 軸上旋轉 (保持水平),然後將此軸設置為固定值,即 X 和 Z 為固定值:
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local sky = Lighting:FindFirstChild("Sky")
local ROTATION_SPEED = 5 -- 每秒度數
RunService.Heartbeat:Connect(function(deltaTime)
sky.SkyboxOrientation = Vector3.new(
30,
(sky.SkyboxOrientation.Y + ROTATION_SPEED * deltaTime) % 360,
0
)
end)
請見 這裡 獲得更多資訊和限制。
範例程式碼
This script uses TweenService to create an oscillating tween on the X axis and RunService to apply the tween's motion plus rotation around the Y axis.
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local sky = Lighting:FindFirstChild("Sky")
local ROTATION_SPEED = 4 -- In degrees per second
local MAX_TILT = 2 -- In degrees
local TILT_SPEED = 4
local currentTilt = Instance.new("NumberValue")
currentTilt.Value = -MAX_TILT
local tweenGoal = { Value = MAX_TILT }
local tweenInfo = TweenInfo.new(TILT_SPEED, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, -1, true)
local tween = TweenService:Create(currentTilt, tweenInfo, tweenGoal)
tween:Play()
RunService.Heartbeat:Connect(function(deltaTime)
sky.SkyboxOrientation = Vector3.new(
currentTilt.Value,
(sky.SkyboxOrientation.Y + ROTATION_SPEED * deltaTime) % 360,
0
)
end)
SkyboxRt
天空盒右側的資產ID。
SkyboxUp
天空盒的頂部表面資產ID。
SunTextureId
使用此天空盒時,太陽的紋理。