# Power Event

{% hint style="info" %}

1. Using the UnityEvent feature on each controller will allow you to add multiple event types, see the demo scene for a clear example on this.
   {% endhint %}

```csharp
void ActivateGenerator()
{
     rumbling = true;
     activateGenerator.Invoke();
}

void DeactivateGenerator()
{
     rumbling = false;
     deactivateGenerator.Invoke();
}
```

{% hint style="info" %}
The events below run the:

* Activate Generator script
* Start an audio effect parented to the object (3D generator sound)
* Turns the red light off
* Turns the green light on

The opposite happens in the deactivate section
{% endhint %}

![](/files/7m8C9EGjdl5XtcqOQr61)

* Below is the script that gets activated by the event

![](/files/iHlpYZQeyQDioKBqVbKs)

```csharp
    public class ActivateGenerator : MonoBehaviour
    {
        [SerializeField] private Renderer[] thisMaterial = null;
        private string emissionName = "_EMISSION";

        [SerializeField] private GameObject[] lights = null;

        public void PowerLights()
        {
            foreach (GameObject lightObjects in lights)
            {
                lightObjects.SetActive(true);
            }

            foreach (Renderer emissiveMaterial in thisMaterial)
            {
                emissiveMaterial.material.EnableKeyword(emissionName);
            }
        }

        public void DeactivateLights()
        {
            foreach (GameObject lightObjects in lights)
            {
                lightObjects.SetActive(false);
            }

            foreach (Renderer emissiveMaterial in thisMaterial)
            {
                emissiveMaterial.material.DisableKeyword(emissionName);
            }
        }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://speedtutoruk.gitbook.io/generator-system-doc/support/power-event.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
