火焰 是多個預製粒子發射類別之一。像其他釋放粒子的對象一樣,火焰會在被父輩到BasePart 和Attachment 時釋放粒子,而在Enabled期間則不會。這個對象有用於在緊急情況下創建快速視覺效果;對於更詳細的工作來說,使用 ParticleEmitter 會比較好。
火焰粒子從BasePart中心發射到他們的父輩。粒子會向上 (+Y) 方向發射;然而,負的 Fire.Heat 可以用於向下 (-Y) 方向發射。使用 作為父而不是使用 來修改排放位置/方向,可以通過修改 或相關屬性來修改排放位置/方向。
當 Enabled 關閉時,現有粒子會繼續渲染,直到它們過期。但是,如果火焰的 Parent 設為 nil 所有現有粒子立即消失,類似於 ParticleEmitter:Clear() 的行為。設置 Parent 為 nil 並返回到原始對象以達到相同效果。如果不希望立即消失,請嘗試將火焰的父處移到一個很遠的位置,然後 在幾秒鐘後移動火焰。這將給現有的粒子時間到期。
火焰物體不會自擁有發出光。為了幫助創建燃燒物件周圍的一致環境,請嘗試添加一個 PointLight 與橙色 Color 。這可以幫助你的火焰看起來更具現實性。
火焰物件由兩個發射器組成。這兩個都受到火焰的 Size , Heat , Color 和 SecondaryColor 的影響各種方式。較小的次要發射器發出的粒子的壽命(和上升高度)比主要發射器發出的粒子長得多(且上升得更遠)。在右邊的視頻中,您可以看到兩個具有不同顏色的發射器。
與實際火焰不同,火焰對象 不會自行擴散 。如果您在遊戲中發現此行為,是因為有一個 Script 造成的。
範例程式碼
This code sample adds Fire to all BasePart in the Workspace named "Torch".
for _, child in pairs(workspace:GetChildren()) do
if child.Name == "Torch" and child:IsA("BasePart") then
local fire = Instance.new("Fire")
fire.Heat = 10
fire.Color = child.Color
fire.SecondaryColor = Color3.new(1, 1, 1) -- White
fire.Size = math.max(child.Size.X, child.Size.Z) -- Pick the larger of the two dimensions
fire.Parent = child
end
end
概要
屬性
決定主要(外部)火焰粒子的顏色。
決定是否發射火焰粒子。
決定粒子發射的速度。
決定次要(內部)火焰粒子的顏色。
決定火焰粒子的尺寸。
在 0 到 1 之間的值,控制粒子效果的速度。
屬性
Color
顏色屬性決定由 Fire 對象發射的較大物件子的顏色。它本質上是火焰外部的顏色。
一般來說,冷卻的火焰在火觸發外面。因此,火焰看起來更接近現實,如果外部部分是紅色或橙色-黃色。整個明亮的火焰看起來不太現實,因此避免將此屬性設為黃色。試試將 PointLight 與 PointLight.Color 作為兄弟加入到 Fire 。這將為環境提供光,讓它與火焰粒子更加融合。
範例程式碼
This code sample adds Fire to all BasePart in the Workspace named "Torch".
for _, child in pairs(workspace:GetChildren()) do
if child.Name == "Torch" and child:IsA("BasePart") then
local fire = Instance.new("Fire")
fire.Heat = 10
fire.Color = child.Color
fire.SecondaryColor = Color3.new(1, 1, 1) -- White
fire.Size = math.max(child.Size.X, child.Size.Z) -- Pick the larger of the two dimensions
fire.Parent = child
end
end
Enabled
啟用屬性,像 ParticleEmitter.Enabled 一樣,決定是否發射火焰粒子。任何已發射的粒子將繼續渲染直到其生命時間到期為止。此屬性有助於在稍後需要時將預製的火焰效果保持關閉。因為火焰粒子在 Fire 對物件的 Instance.Parent 設置為 nil 時被摧毀,這個屬性有助於允許現有粒子在摧毀火焰對象之前有機會過期。請參閱下面的功能。
local Debris = game:GetService("Debris")
local part = script.Parent
function douseFlames(fire)
fire.Enabled = false -- No more new particles
Debris:AddItem(fire, 2) -- Remove the object after a delay (after existing particles have expired)
end
douseFlames(part.Fire)
範例程式碼
This code sample allows a player to click the parent BasePart to toggle a fire effect.
local part = script.Parent
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
local fire = Instance.new("Fire")
fire.Parent = part
local light = Instance.new("PointLight")
light.Parent = part
local function onClick()
fire.Enabled = not fire.Enabled
light.Enabled = fire.Enabled
end
clickDetector.MouseClick:Connect(onClick)
Heat
熱量屬性決定粒子從 Fire 對物件上發射的速度。範圍只限於[-25, 25]。正值位於父 BasePart 或 Attachment 的上方 (+Y) 方向。它也會影響內部粒子的 ParticleEmitter.Acceleration 。以下,您可以看到更高的熱對火焰粒子的速度/加速的影響(左有熱量=9,右有熱量=18)。
範例程式碼
This code sample adds Fire to all BasePart in the Workspace named "Torch".
for _, child in pairs(workspace:GetChildren()) do
if child.Name == "Torch" and child:IsA("BasePart") then
local fire = Instance.new("Fire")
fire.Heat = 10
fire.Color = child.Color
fire.SecondaryColor = Color3.new(1, 1, 1) -- White
fire.Size = math.max(child.Size.X, child.Size.Z) -- Pick the larger of the two dimensions
fire.Parent = child
end
end
LocalTransparencyModifier
SecondaryColor
次要顏色屬性決定由 Fire 對象發射的更小粒子的顏色。它本質上是火焰內部部分的顏色。以下,您可以看到火焰的次要顏色設為白色與較大的外部粒子區分,其中 Fire.Color 設為藍色。應注意,內部粒子使用 1 的 ParticleEmitter.LightEmission,因此黑暗的顏色會使粒子變得透明(因此黑色將停止渲染內部粒子)。
範例程式碼
This code sample adds Fire to all BasePart in the Workspace named "Torch".
for _, child in pairs(workspace:GetChildren()) do
if child.Name == "Torch" and child:IsA("BasePart") then
local fire = Instance.new("Fire")
fire.Heat = 10
fire.Color = child.Color
fire.SecondaryColor = Color3.new(1, 1, 1) -- White
fire.Size = math.max(child.Size.X, child.Size.Z) -- Pick the larger of the two dimensions
fire.Parent = child
end
end
Size
此特性決定火焰粒子的尺寸。範圍必須為 2 到 30。與 ParticleEmitter.Size 不同,火焰的實際尺寸不會與等值的螺柱尺寸 1:1 匹配;它有點小一點。
為了使環境更加緊密,請嘗試將 PointLight 添加到 Fire 物件象的兄弟。將 PointLight.Brightness 和 PointLight.Range 設為此特性的比例,以產生更多的光,使火焰更大。
範例程式碼
This code sample adds Fire to all BasePart in the Workspace named "Torch".
for _, child in pairs(workspace:GetChildren()) do
if child.Name == "Torch" and child:IsA("BasePart") then
local fire = Instance.new("Fire")
fire.Heat = 10
fire.Color = child.Color
fire.SecondaryColor = Color3.new(1, 1, 1) -- White
fire.Size = math.max(child.Size.X, child.Size.Z) -- Pick the larger of the two dimensions
fire.Parent = child
end
end