我的信息没有显示在统一上

时间:2014-08-05 01:51:32

标签: c# unity3d

所以,我有3个脚本。一个控制播放器的一切,另一个控制教程的一切,另一个只有教程对象的信息。我试图在玩家进入触发器时显示教程消息。我的一个变量不起作用我认为它应该如何。这是与我的问题相关的代码(第一和第三种方法没有完全显示,因为它们很长)。

它访问教程脚本的Player脚本:

void OnTriggerEnter(Collider other) 
//detects tutorial
    if (other.transform.tag == "Tutorial")
    {
        tutorial = tutorial.GetComponent<Tutorial>();
        tutorial.showLevelTutorial ();
    }

教程类:

public void showLevelTutorial()
{
    getLevelInfo (); //gets info from trigger on what to display
    showMessage = true; //sets the message to show

    if (messageNum == 2) //gets the timer to start counting
    {
        count = true;
    }
}
/*
 * called from the showLevelTutorial method. It gets info from the trigger.
 */
void getLevelInfo()
{
    levelPrompt = trigger.getPrompt ();
    messageNum = trigger.getNum ();
}
void OnGUI()
{
 //levelTutorial
    if (levelTutorial)
    {
        if (showMessage) //shows tutorial
        {
            print ("about to show message");
            if (messageNum == 2)
            {
                if (timer <= 200)
                    GUI.Label(new Rect(Screen.width/2 - Screen.width/2 *.5f, Screen.height/2 - Screen.height/2 * .5f, 600, 70), levelPrompt, skin.GetStyle ("Tutorial"));
                if (timer > 200 && timer <= 400)
                    GUI.Label (new Rect(Screen.width/2 - Screen.width/2 *.75f, Screen.height/2 + Screen.height/2 * .1f, 300, 70), "This will take you back to your home so that you can buy markers.", skin.GetStyle ("Tutorial"));
                if (timer > 400 && timer <= 600)
                    GUI.Label (new Rect(Screen.width/2 + Screen.width/2 *.3f, Screen.height/2 + Screen.height/2 * .1f, 280, 70), "This will take you to the next level.", skin.GetStyle ("Tutorial"));
                if (timer > 600)
                    GUI.Label (new Rect(Screen.width/2 - Screen.width/2 *.5f, Screen.height/2 - Screen.height/2 * .5f, 600, 70), "For now, let's go back home.", skin.GetStyle ("Tutorial"));
            }
            else
            {
                setTime ();
                Rect TutorialRect = new Rect(Screen.width/2 - (Screen.width*.5f/2), Screen.height/2 - (Screen.height*.5f/2), Screen.width *.5f, Screen.height *.5f);
                GUI.Box (TutorialRect, "");

                if (GUI.Button (new Rect(TutorialRect.x + TutorialRect.width - 170, TutorialRect.y + TutorialRect.height - 60, 150, 40), "Go"))
                {
                    showMessage = false;
                    setTime ();
                }
                GUI.Label(new Rect(TutorialRect.x + 40, TutorialRect.y + 30, TutorialRect.x, 70), levelPrompt, skin.GetStyle ("Tutorial"));
            }
        }
    }
}

我测试了这段代码中的所有变量,我绝对无法弄清楚为什么showMessage变量在showLevelTutorial方法中为真,然后在onGUI方法中再次突然变为false。没有任何声明甚至将showMessage设置为false,可以在此处访问。

我真的很感激这里的一些帮助! :)

0 个答案:

没有答案