鸟语天空
UGUI—UIButtonScale
post by:追风剑情 2022-7-8 15:17
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// 按钮缩放效果
/// </summary>
public class UIButtonScale : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
    [SerializeField]
    private RectTransform rectTransform;
    [SerializeField]
    private Vector2 downScale = new Vector2(1.1f, 1.1f);
    [SerializeField]
    private Vector2 upScale = Vector2.one;

    private void Awake()
    {
        if (rectTransform == null)
            rectTransform = this.GetComponent<RectTransform>();
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        rectTransform.localScale = downScale;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        rectTransform.localScale = upScale;
    }
}
评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容