> For the complete documentation index, see [llms.txt](https://speedtutoruk.gitbook.io/generator-system-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://speedtutoruk.gitbook.io/generator-system-doc/support/power-event.md).

# 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 %}

![](https://2353973356-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mbkr7k2TzEBCzIaxME2%2Fuploads%2FrJ5gjrxBpGjG6oLBtZhm%2FGeneratorEvents.JPG?alt=media\&token=f9a4c5bf-691e-4d8b-9572-d6143d2b2dd7)

* Below is the script that gets activated by the event

![](https://2353973356-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mbkr7k2TzEBCzIaxME2%2Fuploads%2FCRiWBbTUI2kOHscwUPLp%2FActivateGenerator.JPG?alt=media\&token=09cea857-5e4c-4131-900c-07140fdc3115)

```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);
            }
        }
```
