> For the complete documentation index, see [llms.txt](https://emptysolutions.gitbook.io/emptyhacks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emptysolutions.gitbook.io/emptyhacks/main/examples/animations-tests/toggle.md).

# 🎬 toggle

Простая луа, изменяющая альфа-канал цвета rect при нажатии на кнопку.

{% code fullWidth="true" %}

```lua
local gizmos = eh_singleton(eh_runtime_gizmos)
local state = false
local animator = animator_factory.create_linear()

events.add("OnGUI", function()
    if GUILayout.Button("test", GUILayout.Width(100), GUILayout.Height(50)) then
        state = not state
    end
    if Event.current.type == EventType.Repaint then
        animator.reversed = state
        animator.animate(Time.deltaTime)
        gizmos.push_image(-1, Rect(0, 100, 30, 30), Texture2D.whiteTexture, Color(1, 1, 1, animator.value), 0, 1)
    end
end)
```

{% endcode %}

<figure><img src="http://kola50g5.beget.tech/animation_button.gif" alt=""><figcaption></figcaption></figure>
