# Bool Var

## Overview

Bool variables are Scriptable Assets that contain a bool value. They can be referenced in any script and be shared around in a project.

## How to use it

To declare a Bool Var use this code. Make sure to have the namespace:

*`using MalbersAnimations.Scriptables;`*

```csharp
using MalbersAnimations.Scriptables;

public class Example : Monobehaviour
{    
    public BoolVar myVar
}
```

This is how it looks in the Inspector:

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FBR3wcGC0oLws8yHtNkCu%2Fimage.png?alt=media&#x26;token=95a41528-578c-46b6-ba1c-1b44dd88efad" alt=""><figcaption></figcaption></figure>

## Variable Reference

There is a better way to use the scriptable variables. Instead of using **`BoolVar`** class, use **`BoolReference`** instead:

```csharp
using MalbersAnimations.Scriptables;
using UnityEngine;

public class Example : MonoBehaviour
{
    public BoolReference myVar = new BoolReference();
}

```

This is how it looks in the Inspector:

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FW2OZXYOyPr1d87Twh9fw%2FUnity_k1izUN3UgD.gif?alt=media&#x26;token=768793ce-d210-4cbf-9f21-57cf951987de" alt=""><figcaption></figcaption></figure>

That way you have the option to use a local value or a Scriptable (global) value.

Sharing scriptable variables is an extremely useful tool to have shared values between scripts.

## Parameters

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F8jcyLGdAwfuyTWq4xXQW%2Fimage.png?alt=media&#x26;token=ee140ba0-b979-404b-af2e-b6f13cf6ae95" alt=""><figcaption></figcaption></figure>

### Value

The actual value of the scriptable variable.

### Debug \[🪲]

When enabled, the console will print a log every time the scriptable variable changes its value

### Description

Developer description to give a better explanation of what the variable does.

## Internal Events

Scriptable Variables can be listened to using the OnValue changed action.

This is the way of using it via script:

```csharp
using MalbersAnimations.Scriptables;
using UnityEngine;

public class Example : MonoBehaviour
{
    public BoolReference myVar = new BoolReference();


    private void OnEnable()
    {
        myVar.Variable.OnValueChanged += OnValueChanged;
    }

    private void OnDisable()
    {
        myVar.Variable.OnValueChanged += OnValueChanged;
    }

    private void OnValueChanged(bool value)
    {
        //listen to value changes here
    }
}
```
