• Make a button on the screen with given screen space position in the current frame. When user clicks the button, the onClick function will be called.

    The origin of screen space is upper-left corner and the positive Y direction is downward.

    The drawn button will only last for one frame. You should put this under the Update function (or a function that is called by the Update function) to keep the button stays in every frame.

    If this function is called by a lifecycle event function, then the onClick function in the fourth parameter could also be considered as a lifecycle event function.

    This means that you can use other functions from this module inside the onClick function, even though the functions are not under the Outside Lifecycle category.

    For example, the code piece below

    import {init_unity_academy_3d, set_start, set_update, instantiate, gui_button, set_position }
    from "unity_academy";
    init_unity_academy_3d();

    const cube = instantiate("cube");

    const cube_update = (gameObject) => {
    gui_button("Button", 1000, 300, 200, 50, ()=>
    set_position(gameObject, 0, 10, 6) // calling set_position inside the onClick function
    );
    };

    set_update(cube, cube_update);

    is correct.

    You can use rich text for the parameter text. For example: gui_button("<color=#AA00FF>Hello World</color>", 100, 100, 200, 50, my_onclick_function);

    Parameters

    • text: string

      The text you want to display on the button.

    • x: number

      The x coordinate of the button (in screen position).

    • y: number

      The y coordinate of the button (in screen position).

    • width: number

      The width for the button.

    • height: number

      The height for the button.

    • onClick: Function

      The function that will be called when user clicks the button on screen.

    Returns void

Generated using TypeDoc