我使用SetAlpha为我使用的面板创建了一个淡入效果,效果很好:
public void AlphaManagement() {
endGamePanel.GetComponent<CanvasRenderer> ().SetAlpha (panelAlpha);
Average.GetComponent<CanvasRenderer> ().SetAlpha (panelAlpha);
BestReaction.GetComponent<CanvasRenderer> ().SetAlpha (panelAlpha);
infoText.GetComponent<CanvasRenderer> ().SetAlpha (gamePanelAlpha);
if (amountOfTries == 10) {
if (fade < 100) {
panelAlpha += 0.01F;
gamePanelAlpha -= 0.1F;
fade++;
}
}
}
现在我用一系列RawImages完成了同样的事情:
public void AlphaManagement() {
GraphBar1.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
GraphBar2.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
GraphBar3.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
GraphBar4.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
GraphBar5.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
GraphBar6.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
GraphBar7.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
GraphBar8.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
GraphBar9.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
GraphBar10.GetComponent<CanvasRenderer> ().SetAlpha(alpha);
if (oScript.amountOfTries == 1) {
if (fade < 100) {
alpha += 0.01F;
fade++;
}
}
}
然而,这根本不起作用。我怀疑它可能是一个RawImage,但我不安全。
答案 0 :(得分:0)
尝试其他UI组件后解决了这个问题。
Raw Image似乎在使用SetAlpha时遇到了问题。我将我的UI组件从RawImage更改为Panels,这解决了我的问题。