範例程式碼
從零開始創建光束
-- 創建附件
local att0 = Instance.new("Attachment")
local att1 = Instance.new("Attachment")
-- 父級到地形(也可以是部件)
att0.Parent = workspace.Terrain
att1.Parent = workspace.Terrain
-- 定位附件
att0.Position = Vector3.new(0, 10, 0)
att1.Position = Vector3.new(0, 10, 10)
-- 創建光束
local beam = Instance.new("Beam")
beam.Attachment0 = att0
beam.Attachment1 = att1
-- 外觀屬性
beam.Color = ColorSequence.new({ -- 一個顏色序列從白色變為藍色
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 255)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 255, 255)),
})
beam.LightEmission = 1 -- 使用加法混合
beam.LightInfluence = 0 -- 光束不受光影響
beam.Texture = "rbxasset://textures/particles/sparkles_main.dds" -- 內建的閃爍紋理
beam.TextureMode = Enum.TextureMode.Wrap -- 包裹以便可以通過 TextureLength 設置長度
beam.TextureLength = 1 -- 重複的紋理長度為 1 研究
beam.TextureSpeed = 1 -- 緩慢的紋理速度
beam.Transparency = NumberSequence.new({ -- 光束在末端淡出
NumberSequenceKeypoint.new(0, 0),
NumberSequenceKeypoint.new(0.8, 0),
NumberSequenceKeypoint.new(1, 1),
})
beam.ZOffset = 0 -- 在光束的位置渲染而不偏移
-- 形狀屬性
beam.CurveSize0 = 2 -- 創建一個彎曲的光束
beam.CurveSize1 = -2 -- 創建一個彎曲的光束
beam.FaceCamera = true -- 光束從每個角度都可見
beam.Segments = 10 -- 默認曲線解析度
beam.Width0 = 0.2 -- 開始時小
beam.Width1 = 2 -- 結束時大
-- 父級光束
beam.Enabled = true
beam.Parent = att0API 參考
屬性
CurveSize0
範例程式碼
曲線大小0
local part = Instance.new("Part")
part.Anchored = true
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Parent = part
local Beam = Instance.new("Beam")
Beam.Attachment0 = attachment0
Beam.Attachment1 = attachment1
Beam.Parent = part
local controlPoint2 = Beam.Attachment0.WorldPosition + (Beam.Attachment0.CFrame.RightVector * Beam.CurveSize0)CurveSize1
範例程式碼
曲線大小1
local part = Instance.new("Part")
part.Anchored = true
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Parent = part
local Beam = Instance.new("Beam")
Beam.Attachment0 = attachment0
Beam.Attachment1 = attachment1
Beam.Parent = part
local controlPoint3 = Beam.Attachment1.WorldPosition - (Beam.Attachment1.CFrame.RightVector * Beam.CurveSize1)Texture
Beam.Texture:ContentId
ZOffset
範例程式碼
層疊光束
-- 創建光束
local beam1 = Instance.new("Beam")
beam1.Color = ColorSequence.new(Color3.new(1, 0, 0))
beam1.FaceCamera = true
beam1.Width0 = 3
beam1.Width1 = 3
local beam2 = Instance.new("Beam")
beam2.Color = ColorSequence.new(Color3.new(0, 1, 0))
beam2.FaceCamera = true
beam2.Width0 = 2
beam2.Width1 = 2
local beam3 = Instance.new("Beam")
beam3.Color = ColorSequence.new(Color3.new(0, 0, 1))
beam3.FaceCamera = true
beam3.Width0 = 1
beam3.Width1 = 1
-- 層疊光束
beam1.ZOffset = 0
beam2.ZOffset = 0.01
beam3.ZOffset = 0.02
-- 創建附加物
local attachment0 = Instance.new("Attachment")
attachment0.Position = Vector3.new(0, -10, 0)
attachment0.Parent = workspace.Terrain
local attachment1 = Instance.new("Attachment")
attachment1.Position = Vector3.new(0, 10, 0)
attachment1.Parent = workspace.Terrain
-- 連接光束
beam1.Attachment0 = attachment0
beam1.Attachment1 = attachment1
beam2.Attachment0 = attachment0
beam2.Attachment1 = attachment1
beam3.Attachment0 = attachment0
beam3.Attachment1 = attachment1
-- 父級光束
beam1.Parent = workspace
beam2.Parent = workspace
beam3.Parent = workspace方法