New UI system set (static) booleans active and inactive

How can I use the UI toggle button to enable and disable bools that I use to check states.
I have a “public static bool RayEnabled;” to set on and off a LineRenderer but I want to be able to change this also from the UI.

public static bool rayEnabled = false;

public void eventOnClick(){
    rayEnabled = !rayEnabled;

Add this function for your UI Button OnClick() event.

Unity tutorials on new UI.