Adjust scene lighting with a button
Change the scene’s light color or intensity when the user clicks a button.
Read time 1 minuteLast updated 2 days ago
Use this example to understand how to change the scene’s light color or intensity when the user clicks a button.
Create a button in your UI Canvas.
- Select UI Canvas in the Hierarchy panel.
- Right-click the UI Canvas and select UI > Button to create a new button.
Create a New Logic script.
- In the Project panel, select the My Logic folder.
- Select Add (+).
- Select New Script. Unity Lite creates a new Logic script in the folder.
- Enter a name for your script and press Enter.
Add the script to a GameObject.
- Select or create a GameObject from the Hierarchy panel.
- From the Inspector panel, select Add Component.
- Choose your Logic script from the list.
Set up the logic in the Logic Editor.
- In the Project panel, double-click the Logic script to open the Logic Editor.
- Drag a When event listener into the Logic Editor.
- Add a Clicked On event inside the When node.
- Create a new variable for the button and set its type to Object.
- Drag the button variable into the Clicked On socket.
- Drag a Set variable value node into the When node.
- Create a new variable for the light and set its type to Light.
- Expand the light variable and select the Color property.
- Drag the Color property into the Set variable value node.
- Click on the color code in the Set variable value node to open the color wheel and choose your desired light color.

Example Logic script to change the light color on button click.
- Close the Logic Editor.
Connect your Button and Light references.
- In the Hierarchy panel, select the GameObject with the attached Logic script.
- Drag your button from the Hierarchy panel into the Button variable reference in your script component.
- Drag your Light object from the Hierarchy panel into the Light variable reference in your script component.