0

私は 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);
        }
    }
}

}

何か案は?ありがとう

4

1 に答える 1