Creating a Light Interactable using Interface.
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.
Go to the ToggleLight script, inherit IInteractable, and create these three variables.
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.
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.
Now, go to the scene and place the lights prefab anywhere, then interact with them.
See you in the next one.
