无法正确运行if(answer = player2)

时间:2016-01-26 14:17:46

标签: javascript

我无法正确运行脚本。我希望你们能在这里帮助我。

我想如果玩家输入正确的答案,我将能够转到另一页,否则我会将他弹回主菜单。

 #pragma strict
     var player = "";
     var score : int = 0; 
     var number : int;
     var number2: int;
     var answer : int;
     var q : int = 0;
     var player2 : int = 0;


     function Start() {
     number = Random.Range(2,9);
     number2= Random.Range(2,9);
     answer = number*number2;

 }
 function update(){
 q = answer;
 player2 = int.Parse(player);

 }
 function OnGUI() {
 var guiStyleA =GUI.skin.GetStyle("Button");
 guiStyleA.fontSize = 20;
 guiStyleA.fontStyle = FontStyle.Normal;

 var guiStyleB = GUI.skin.GetStyle("Label");
 guiStyleB.fontSize = 25;
 guiStyleB.fontStyle = FontStyle.Normal;

    GUI.skin.box.fontSize = 20;

    GUI.skin.textField.fontSize =20;

 var guiStyleC = GUI.skin.GetStyle("Label");
 guiStyleC.fontSize = 20;
 guiStyleC.fontStyle = FontStyle.Italic;        

            GUI.Box(Rect (150,10,50,30),score.ToString());
            GUI.Label(Rect(45,70,200,150), number + " X "+ number2 + " = " + player);   
            player = GUI.TextField( Rect (135, 130, 50, 30), player);
            GUI.Label(Rect(10, 100,200,150),"Please Fill in your answer here : " + "        ",guiStyleC);

             if ( GUI.Button ( Rect (100, 200, 70, 40) , "Submit" ) ){ //just a button
                CheckAnswer();

 }
 }
 function CheckAnswer() {
 if (q == player2){
    score += 1;
    Application.LoadLevel (32);
    }else {
    Application.LoadLevel (35);}


}

1 个答案:

答案 0 :(得分:0)

我猜您应该尝试偶尔调用“更新”功能。