Lets pick up where we left off previously with our Earth. We have something like this.

Putting in a sphere
Let’s create a sphere that will act as our Interacting Object. In the Hierarchy window, right-click, select 3D Object > Sphere

A sphere will appear, move it away from Earth

Adding an Interactable Box
In the Project Window, go to MyInteractionKit > Prefabs and drag the Interactable Box into the scene.

A new Interactable Box will appear.

In the Inspector window, type in a new name for the box, I will use “Interactable Box(sphere)”. Press Enter and its name will be changed

Next, lets find where is the box? Select our Interactable Box in the Hierarchy and press F so that Unity focuses on the box.

Move the Interactable Box and put it together with our Sphere

In the Interactables component of the InteractableBox, find the OnInteract() list. Press + to add a new Action

You will have something like this

Adding the Toggle Component
Press the Add Component button.

A selector window appears, in the search panel, type in Toggle. A bunch of Toggle results will appear, select Toggle (MyInteractionKit)

A Toggle component now appears in Inspector window

Meet the Toggle component
The Toggle component is like an On/Off switch. Everytime you trigger it, it will switch from isOn to isOff or, isOff to isOn.
Toggle have a few settings:
On – If this is checked, the current state of toggle is On
Is On() – The list of actions to execute when the Toggle is On
Is Off () – The list of actions to execute when the Toggle is Off
Triggering the Toggle
To trigger the Toggle component, drag and drop the Toggle component to the Object area of the Interactables component.

It will now look like this

Press the Function Dropdown, and Select Toggle > ToggleOnOff()

This will now trigger the Toggle from on to off and vice versa.
In the Interactables component, change the Description text to Press to On/Off light.

Next, let’s press Play, move towards the Sphere and press F key to Interact with it. You will notice that the On value will check/uncheck as you press F


Reacting to Toggle events
Now that we have Toggle on/off, lets make it so that if toggle is On, we shut down the Directional Light in the scene.
At the Is On() list, press +

An item will appear on the list, exactly like it does when we deal with Interactables.

Drag and Drop the Directional Light to the object area of the item.

You will have something like this

Click the Function dropdown menu and select GameObject > SetActive (bool)

You will have something like this.

This will now Disable the light when the toggle Is On. Press Play and Interact with the sphere to test. The light will turn off.

Stop Playing. Now let’s setup the light so that when the toggle isOff, the light is Enabled
At the Is Off() list, press +

You will have something like this

Drag and Drop the Directional Light to the object area of the item.

You will have something like this

Click the Function dropdown menu and select GameObject > SetActive (bool)

You will have something like this

Check the checkbox, so that the Directional Light will be enabled when Trigger is Off

Press Play, and now you can turn the lights on/off.
