我通過基於距離光源的距離改變顏色,在ROBLOX中製作了基本的基於瓷磚的照明系統。我想能夠放置多個光源,但我遇到了一些問題:基於瓷磚的照明系統中的多個光源
當我嘗試添加另一個光源時,性能有點下降(從全60到45-50)。
它無法正常工作,光源切斷了彼此的光線等。
我的代碼:
local sp = script.Parent
local lightBrightness
local lightPower = 1
local grid = game.ReplicatedStorage.Folder:Clone()
grid.Parent = workspace.CurrentCamera
local lightSource = game.ReplicatedStorage.LightSource:Clone()
lightSource.Parent = workspace.CurrentCamera
lightSource.Position = grid:GetChildren()[math.random(1,#grid:GetChildren())].Position
for _, v in pairs(grid:GetChildren()) do
if v:IsA("Part") then
game["Run Service"].RenderStepped:connect(function()
local lightFact = (lightSource.Position-v.Position).magnitude
lightBrightness = lightPower - (lightFact*10)/255
if lightFact < 35 then
v.SurfaceGui.Frame.BackgroundColor3 = v.SurfaceGui.Frame.BackgroundColor3.r >= 0 and Color3.new((100/255)+lightBrightness*.85,(50/255)+lightBrightness*.85,10/255+lightBrightness) or Color3.new(0,0,0)
elseif lightFact > 35 and lightFact < 40 and v.SurfaceGui.Frame.BackgroundColor3.r > 0 then
v.SurfaceGui.Frame.BackgroundColor3 = Color3.new(0,0,0)
end
end)
end
end