Light behaves a lot like a component, but isn’t one. As such, it must be added using the following syntax instead:
1 |
inst.entity:AddLight() |
Light Methods
Name | Parameter | Returns | Description |
---|---|---|---|
SetIntensity | percent | nil | how bright the light is |
SetRadius | number | nil | how far the light shines |
SetFalloff | percent | nil | how rapidly the light goes from full intensity to none |
SetColour | r,g,b | nil | red,green,blue in percent |
Enable | boolean | nil | true activates the light, false disables it (it keeps its settings) |
Comparison Pictures
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
local function turnon(inst) -- enable light inst.Light:Enable(true) inst.AnimState:PlayAnimation("idle_on") [...] end local function turnoff(inst) --disable light inst.Light:Enable(false) inst.AnimState:PlayAnimation("idle_off") [...] end local function fuelupdate(inst) --calculate brightness using math functions local fuelpercent = inst.components.fueled:GetPercent() inst.Light:SetIntensity(Lerp(0.4, 0.6, fuelpercent)) --lerp is a mathematical function inst.Light:SetRadius(Lerp(3, 5, fuelpercent)) inst.Light:SetFalloff(.9) end local function fn() [...] inst.entity:AddLight() --light is not a component inst.Light:SetColour(180/255, 195/255, 150/255) --clever way you can use the rgb-system fuelupdate(inst) end |
Of course you can just enable it at all times, or at fixed brightness. You can use the common RGBÂ system using divisions like above, to implement easily pickable colours (for example using colorpicker)