31 lines
812 B
C#
31 lines
812 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class MenuButton : MonoBehaviour
|
|
{
|
|
public Text text;
|
|
|
|
public Image background;
|
|
|
|
public Image backgroundActive;
|
|
|
|
private void Start()
|
|
{
|
|
UpdateBackground();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
UpdateBackground();
|
|
}
|
|
|
|
public void UpdateBackground()
|
|
{
|
|
float preferredWidth = text.preferredWidth;
|
|
background.rectTransform.sizeDelta = new Vector2(preferredWidth + 85f, background.rectTransform.sizeDelta.y);
|
|
background.rectTransform.anchoredPosition = new Vector2(-110f, background.rectTransform.anchoredPosition.y);
|
|
backgroundActive.rectTransform.sizeDelta = new Vector2(background.rectTransform.sizeDelta.x + 6f, background.rectTransform.sizeDelta.y);
|
|
backgroundActive.rectTransform.anchoredPosition = background.rectTransform.anchoredPosition;
|
|
}
|
|
}
|