當我淡入淡出場景並嘗試淡入原始屏幕時,遇到黑屏。例如,從暫停屏幕返回到主菜單讓我看到黑屏,我認爲這是我的代碼的問題。我應該如何解決這個問題?在統一中淡入場景無法正常工作
using UnityEngine;
using System.Collections;
public class Fading : MonoBehaviour
{
public Texture2D fadeOutTexture;
public float fadeSpeed = 0.8f;
private int drawDepth = -1000;
private float alpha = 1.0f;
private int fadeDir = -1;
void OnGUI()
{
alpha += fadeDir * fadeSpeed * Time.deltaTime;
alpha = Mathf.Clamp01(alpha);
GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha);
GUI.depth = drawDepth;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);
}
public float BeginFade (int direction)
{
fadeDir = direction;
return (fadeSpeed);
}
void OnLevelWasLoaded()
{
alpha = 1;
BeginFade(-1);
}
}
試着問上http://answers.unity3d.com/你很可能會得到一個答案有 – kentor
你真的不應該使用古代遺留下來的GUI系統。現在只使用普通的Unity.UI。使用遺留系統只是不切合實際。 – Fattie
由於kentor提到有這個容易googleable〜100完整的工作示例http://answers.unity3d.com/questions/780323/unity-ui-fading-canvaspanel.html – Fattie