粒子發射器設置完成後,現在可以通過腳本來播放爆炸囉
該腳本通過檢查玩家是否碰到陷阱來運作。每當它檢測到玩家時,粒子就會發射,玩家就會死亡
local trapObject = script.Parent
local particleEmitter = trapObject:FindFirstChild("Explosion")
local EMIT_AMOUNT = 100
local trapObject = script.Parent
local particleEmitter = trapObject:FindFirstChild("Explosion")
local EMIT_AMOUNT= 30
local function killPlayer(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
trapObject.Touched:Connect(killPlayer)
在腳本中,粒子是使用 Emit() 函數來發射的,而這會產生多個粒子的一次性爆發
local trapObject = script.Parent
local particleEmitter = trapObject:FindFirstChild("Explosion")
local EMIT_AMOUNT= 100
local function killPlayer(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid.Health = 0
particleEmitter:Emit(EMIT_AMOUNT)
end
end
trapObject.Touched:Connect(killPlayer)
https://developer.roblox.com/assets/blt588d95310e04b123/28aa03cc37d63c68f95f009aad36374f.mp4
只需對本單元中的範例進行一些更改,你就可以創建出各種不同的效果。一些替代方案包括用於收集可收集物品的火花,或用於指向型彈藥導致的爆炸