UGUI—不规则按钮

作者:追风剑情 发布于:2019-9-26 23:37 分类:Unity3d

参考 https://www.jianshu.com/p/e82b22a9c5eb

一、导入一张按钮图,并设置类型为Sprite (2D and UI)

1111.png

必须勾上Read/Write Enabled

二、更改Image的alphaHitTestMinimumThreshold值(alpha小于此值的区域不会响应点击事件)

把下面的脚本挂在Button上

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AlphaButton : MonoBehaviour
{
    public float alphaHitTestMinimumThreshold = 0.1f;
    void Awake()
    {
        this.GetComponent<Image>().alphaHitTestMinimumThreshold = alphaHitTestMinimumThreshold;
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号   sitemap

川公网安备 51019002001593号