# SLight

## Index

### Properties Index

| Property Name                                   |
| ----------------------------------------------- |
| bool [**Enabled** ](#enabled)`get` `set`        |
| float [**Range** ](#range)`get` `set`           |
| float [**SpotAngle** ](#spotangle)`get` `set`   |
| float [**Intensity** ](#intensity)`get` `set`   |
| SVector [**Color** ](#color)`get` `set`         |
| SLightType [**Type** ](#type)`get` `set`        |
| SGameObject [**GameObject** ](#gameobject)`get` |

## Properties

### Enabled

bool **Enabled** `get` `set`

*Enable/Disable this light.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Light.Enabled = false
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make the object Enable/Disable it's Light component
--[Add "light" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
light = Space.Host.GetReference("light").Light


OnClick = function()
light.Enabled =  not light.Enabled
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### Range

float **Range** `get` `set`

*Get/Set the effective range of the light source.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Light.Range = 8.0
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set the Light's range
--[Add "slider" and "light" references to the Scripting Runtime component]

light = Space.Host.GetReference("light").Light
slider = Space.Host.GetReference("slider").UISlider

OVC = function()
light.Range = (slider.Value * 100) --(from 0 to 100)
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### SpotAngle

float **SpotAngle** `get` `set`

*The angle of the light's spotlight cone in degrees.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Light.SpotAngle = 50
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set the Light's Spot Angle
--[Add "slider" and "light" references to the Scripting Runtime component]

light = Space.Host.GetReference("light").Light
slider = Space.Host.GetReference("slider").UISlider

light.Type = 2 --it has to be Spot type 

OVC = function()
light.SpotAngle = (slider.Value * 178) + 1 --(from 1 to 179)
end

slider.OnValueChanged(OVC)
```

{% endtab %}
{% endtabs %}

### Intensity

float **Intensity** `get` `set`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
LightIntensity = Space.Host.ExecutingObject.Light.Intensity
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set the Light's Intensity
--[Add "slider" and "light" references to the Scripting Runtime component]

light = Space.Host.GetReference("light").Light
slider = Space.Host.GetReference("slider").UISlider


OVC = function()
light.Intensity = (slider.Value * 8) --(from 0 to 8)
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### Color

[SVector](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/svector) **Color** `get` `set`

Get/Set the color of the light.

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Light.Color = Color.Red
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--clicking the object will open a color picker that changes Light's color
----[Add "light" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
light = Space.Host.GetReference("light").Light

OnChange = function(SColor) 
 light.Color = SColor
end

OnSelect = function(SColor)
 light.Color = SColor
end

OnCancel = function()
end

OnClick = function()
Space.Dialogues.ColorPicker("Pick a color","Ok", OnChange, OnSelect, OnCancel, Color.Red)
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### Type

int **Type** `get` `set`

Get/Set the type of light this source is. 0 = Directional, 1 = Point, 2 = Spot, 3 = Area.

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Light.Type = 0
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--Clicking the object toggles between the 4 different light types
--[Add "light" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
light = Space.Host.GetReference("light").Light

OnClick = function()
  
  if light.Type == 3 then
    light.Type = 0
  else light.Type = light.Type + 1
  end
  
end

thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### GameObject

[SGameObject](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/sgameobject) **GameObject** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
theGameObject = Space.Host.ExecutingObject.Light.GameObject
```

{% endtab %}
{% endtabs %}
