準備條件:
1、在圖片導入時,選擇Texture Type爲“Advanced”,然後勾選“Read/Write Enabled”選項
2、添加以下腳本,並添加到當前物體上
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UnruleButton : MonoBehaviour
{
public float alpha = 0.5f;
private Image buttonImage;
void Start()
{
buttonImage = GetComponent<Image>();
if(buttonImage)
{
buttonImage.eventAlphaThreshold = alpha;
}
}
}
3、添加”Button“組件
4、添加按鈕事件
注意事項:
buttonImage.eventAlphaThreshold 取值範圍在0.0f 到 1.0f之間,是a通道的除以a通道允許的最大值得出的一個比例值