BGJ-2022.1/Assets/Scripts/UI/ButtonBehaviour.cs

31 lines
879 B
C#
Raw Normal View History

using UnityEngine;
using UnityEngine.EventSystems;
using TMPro;
namespace UI
{
public class ButtonBehaviour : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
[SerializeField] private Vector2 offset = new Vector2(8, -8);
private TMP_Text text = null;
private Vector3 initialTextPosition = Vector3.zero;
public void OnPointerDown(PointerEventData eventData)
{
text.transform.localPosition = initialTextPosition + (Vector3)offset;
}
public void OnPointerUp(PointerEventData eventData)
{
text.transform.localPosition = initialTextPosition;
2022-02-26 20:09:12 +03:00
UIManager.Instance.PlayClickSound();
}
private void Start()
{
text = GetComponentInChildren<TMP_Text>();
initialTextPosition = text.transform.localPosition;
}
}
}