在播放模式中淡出,但在执行文件中不淡出[Unity 5 - c#]

本文关键字:淡出 Unity 执行 模式 播放 文件 | 更新日期: 2023-09-27 18:06:44

我对Unity 5和c#脚本有点陌生。我正致力于Unity的Turorial"Roll a Ball"的进化,现在我已经在游戏开始时插入了一个菜单和一个闪屏(当然是在Unity之后)。它工作得非常好.....但只能在Unity编辑器中,在播放模式中。当我创建可执行文件时,闪屏背景的淡入淡出效果不起作用(只有文本),在文本淡入淡出后,游戏立即跳转到下一个场景(菜单)

这是脚本:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class SplashController : MonoBehaviour {
private float timer;      //simply a...timer
private float now_alpha;  //temporary variable storing the background alpha
private int in_out;       //flag variable storing the current fading direction (1 = fade backgr. in; 0 = fade text in; -1 = fade all out)
private Color temp;       //temporary variable storing the text alpha
public RawImage image;    //background
public Text presents;     //a text that has to be displayed
public int load_me;       //the next scene to be loaded
void SetAlpha(float x)    //this sets the backgr. alpha
{
    Color temp = image.color;
    temp.a = x;
    now_alpha = x;
    image.color = temp;
}
void Start()
{
    timer = 4.0f;  
    in_out = 1;    //fade direction = backgr. in
    temp = presents.material.color;  //hides the text
    temp.a = 0f;
    presents.material.color = temp;
}
void Fade()
{
    if (in_out == 1)  //fades the back in
    {
        now_alpha += System.Convert.ToSingle(0.5 * Time.deltaTime);
        SetAlpha (now_alpha);
    }
    else if (in_out == -1)  //fades the back out
    {
        now_alpha -= System.Convert.ToSingle(0.5 * Time.deltaTime);
        SetAlpha (now_alpha);
        if (now_alpha <= 0.02)
        {
            timer = 0;
        }
    }
}
void FadeText()
{ 
    if (in_out == 0)  //fades the text in
    {
        temp = presents.material.color;
        temp.a += System.Convert.ToSingle(0.5 * Time.deltaTime);
        presents.material.color = temp;
    }
    else if (in_out == -1)  //fades the text out
    {
        temp = presents.material.color;
        temp.a -= System.Convert.ToSingle(0.5 * Time.deltaTime);
        presents.material.color = temp;
    }
}
void Update()
{
    timer -= Time.deltaTime;
    if (timer >= 0)  //before the 0
    {
        if (in_out == 1)  //step 1: fade the backgr. in
        {
            Fade();
        }
        else if (in_out == 0)  //step 2: fade the text in
        {
            FadeText();
        }
        else if (in_out == -1)  //step 3: fade all out
        {
            FadeText();
            Fade();
        }
    }
    else  //after the 0 and before the next step
    {
        if (in_out == 1)
        {
            timer = 4.0f;  
            in_out--;      //changes fading direction/phase
        }
        else if (in_out == 0)
        {   
            timer = 4.0f;
            in_out--;
            temp = presents.material.color;  //idk why, but after being faded in, the text is bold and so I have to turn it normal
            temp.a = 1;
            presents.material.color = temp;
        }
        else if (in_out == -1)
        {   
            Application.LoadLevel (load_me);
        }
    }
}
}

任何想法?由于

在播放模式中淡出,但在执行文件中不淡出[Unity 5 - c#]

我有同样的问题…我通过在编辑->项目设置->图形设置中添加标准着色器来修复。

在数组Always Included Shaders中增加数组的大小并搜索标准着色器

希望它对你也有用。中科院