A
A
Alexander Petrov2022-01-10 00:21:38
Unity
Alexander Petrov, 2022-01-10 00:21:38

MouseDown and MouseUp events for button in UI Toolkit?

I’ll immediately note that the button was created not in Canvas, but through UI Builder.

I figured out the lesson how to catch a button click:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class UIButtons : MonoBehaviour
{

    public Button delete;

    // Start is called before the first frame update
    void Start()
    {
        var root = GetComponent<UIDocument>().rootVisualElement;

        delete = root.Q<Button>("Delete");

        delete.clicked += Clicked;

    }

    // Update is called once per frame
    void Clicked()
    {
        Debug.Log("CLICKED");
    }
}


And how to catch the MouseDown and MouseUp events for the same button?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question