Button
Hex UI buttons support multiple event types, auto-fitting, and a dynamic content manager. If you want to manage the content manually, you can enable the ‘Use Custom Content’ option via the button settings.
![](https://docs.michsky.com/wp-content/uploads/2024/05/Unity_N464PwNDMg.gif)
Buttons automatically adjust their width based on the content. If you want to adjust the width manually, you can disable the ‘Auto-Fit Content’ option.
![](https://docs.michsky.com/wp-content/uploads/2022/11/image_2022-12-11_161932142.png)
using UnityEngine;
using Michsky.UI.Hex; // Namespace
public class SampleClass : MonoBehaviour
{
[SerializeField] private ButtonManager myButton;
[SerializeField] private Sprite icon;
void Start()
{
// Change interaction state
myButton.Interactable(true);
// Set button icon and text
myButton.SetIcon(icon);
myButton.SetText("Button Text");
// Enable or disable icon and text
// Requires UpdateUI() to be called
myButton.enableIcon = true;
myButton.enableText = true;
// Enable or disable button sfx
myButton.useSounds = true;
// Add button events
myButton.onClick.AddListener(TestFunction);
myButton.onHover.AddListener(TestFunction);
myButton.onLeave.AddListener(TestFunction);
myButton.onDoubleClick.AddListener(TestFunction);
// Apply the changes and update the UI
myButton.UpdateUI();
}
void TestFunction()
{
Debug.Log("Event test");
}
}
C#