- Home /
 
App gets stuck on WebGL
I've got a problem with Unity WebGL app. It is a multiplication quiz. When I enter wrong answer the whole webpage gets stuck, but when I enter the right answer - all is OK. How can I fix this wrong answer problem?
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Questions : MonoBehaviour {
 public Text label;
 public InputField input;
 public Text rightText;
 public Text wrongText;
 public Button NextBtn;
 private float multiplicand, multiplier, product;
 // Use this for initialization
 void Start () {
     NextBtn.enabled = false;
     GenerateNewQuestion();
     input.Select(); //focus cursor to input field
     Button btn = NextBtn.GetComponent<Button>();
     btn.onClick.AddListener(TaskOnClick);
     
 }
 void TaskOnClick()
 {
     NextBtn.enabled = false;
     GenerateNewQuestion();
     input.enabled = true;
     input.text = "";
     rightText.text = "";
     wrongText.text = "";
     
 }
 void GenerateNewQuestion()
 {
     multiplicand = Mathf.Round(Random.Range(0f, 10f));
     multiplier = Mathf.Round(Random.Range(0f, 10f));
     product = multiplicand * multiplier;
     label.text = multiplicand + "*" + multiplier + "=";
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.GetKeyDown(KeyCode.Return)) //enter key
     {
         CheckAnswer();
     }
     
 }
 void CheckAnswer()
 {
     float userAnswer;
     // if input is valid (is a number)
     if(float.TryParse(input.text, out userAnswer))
     {
         // if the two values are the same
         if (Mathf.Approximately(userAnswer, product))
         {
             rightText.text = ("Right!  " + product);
             input.enabled = false;
             NextBtn.enabled = true;
         }
         else
         {
             wrongText.text = ("Wrong!  " + product);
             input.enabled = false;
             NextBtn.enabled = true;
         }
     }
     else
     {
         //input text is invalid, (e.g. text is blank or is not a number)
         input.text = "";
         
     }
 }
 
               }
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Creating an app for mobile and browsers 1 Answer
i have a problem with reloading with Time.time 2d game c# Unity 2020.2 1 Answer
Videos in WebGL 0 Answers
Error when loading Unity WebGL 1 Answer
Multiple Cars not working 1 Answer