codeAPI Reference
Sandbox.Light
Sandbox.Light
Illuminates the scene.
Overview
Light component adds dynamic lighting to GameObjects. Supports point, spot, and directional lights.
Setup
CSHARP
var light = gameObject.Components.Create<Light>();
light.LightType = LightType.Point;Light Types
Properties
| Property | Description |
|---|---|
| LightType | Point or Spot |
| Color | Light color (white, warm, etc.) |
| Brightness | Intensity |
| Range | Falloff distance |
| Attenuation | Falloff curve |
Spot Light
CSHARP
var spot = gameObject.Components.Create<Light>();
spot.LightType = LightType.Spot;
spot.InnerConeAngle = 30f;
spot.OuterConeAngle = 45f;
spot.Color = Color.White;
spot.Brightness = 1000f;
spot.Range = 1000f;Point Light
CSHARP
var point = gameObject.Components.Create<Light>();
point.LightType = LightType.Point;
point.Color = new Color(1, 0.8f, 0.6f); // Warm
point.Brightness = 500f;
point.Range = 500f;Shadow
CSHARP
light.Shadows = ShadowType.Cascade;
// or
light.Shadows = ShadowType.Single;Animated
CSHARP
// Flickering torch
protected override void OnUpdate()
{
light.Brightness = 500f + Random.Shared.Float(-50, 50);
}Performance
- Limit overlapping lights
- Use lower brightness for distant lights
- Disable shadows for small/unimportant lights
- Bake static lighting when possible
Was this helpful?