UGUI—UIButtonScale

作者:追风剑情 发布于:2022-7-8 15:17 分类:Unity3d

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;
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号