Sitemap

Creating a Light Interactable using Interface.

2 min readJul 15, 2025

Objective: Creating a Light Interactable using the Interface.

When working with prefab, it's recommended to open it in the prefab editor. It's best practice to use most components there since overriding the prefab can cause connection issues for nested prefabs.

In the first step, open our light prefab, then add the Interactable script, create the ToggleLight script, and attach it. Dont forget to add sphere collider.

Press enter or click to view image in full size

Go to the ToggleLight script, inherit IInteractable, and create these three variables.

Press enter or click to view image in full size

Create the Awake method and get the materials option through the meshRenderer, and set the emission of the material based on the bool value.

We can allow an artist of level designer ability to set the light off or on when the game starts by default using the bool variable. Just add SerializeField to the bool at the beginning of the private keyword.

Note: Our light is turned on or off using emission material, which is found in the MeshRender, under materials options.

SetColor takes a color name and value, but make sure to multiply the value by the number to make the color brighter.

Press enter or click to view image in full size

Go to the Interact Method and allow play to turn the light on or off by setting the bool to false if it was true or vice versa, then set the emission value like above.

Press enter or click to view image in full size

Now, go to the scene and place the lights prefab anywhere, then interact with them.

Press enter or click to view image in full size

See you in the next one.

--

--

Suleiman Abdullah
Suleiman Abdullah

Written by Suleiman Abdullah

My name is Suleiman Abdullah. I learn game development and share what I learn by writing articles. :https://ko-fi.com/suleimanabdullah

No responses yet