using UnityEngine;
using UnityEngine.UI;
using TMPro;
///
/// Simple script to help create action button prefabs programmatically
/// This can be attached to a prefab or used to create buttons at runtime
///
public class ActionButtonCreator : MonoBehaviour
{
[Header("Button Creation")]
public bool createButtonOnStart = false;
public string buttonText = "Action";
public Sprite buttonIcon;
void Start()
{
if (createButtonOnStart)
{
CreateActionButton();
}
}
///
/// Creates a complete action button with icon and text
///
public static GameObject CreateActionButton(Transform parent, string buttonName = "ActionButton")
{
// Create main button object
GameObject buttonObj = new GameObject(buttonName);
buttonObj.transform.SetParent(parent, false);
// Add RectTransform
RectTransform rectTransform = buttonObj.AddComponent();
rectTransform.sizeDelta = new Vector2(60, 60);
// Add Image component for background
Image backgroundImage = buttonObj.AddComponent();
backgroundImage.color = new Color(0.2f, 0.2f, 0.2f, 0.8f);
backgroundImage.type = Image.Type.Sliced;
// Add Button component
Button button = buttonObj.AddComponent