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上

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class AlphaButton : MonoBehaviour
  7. {
  8. public float alphaHitTestMinimumThreshold = 0.1f;
  9. void Awake()
  10. {
  11. this.GetComponent<Image>().alphaHitTestMinimumThreshold = alphaHitTestMinimumThreshold;
  12. }
  13. }

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号