I have a problem when i make this script that first time when click button it work but after that it stuck and
not work as a first time …the random number change every time when i click the button
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class limit : MonoBehaviour {
public Button check;
public Text checkText;
public Text score;
public int scor;
public Text gues;
private int guess;
public Text state;
public int numb;
public InputField input1;
public Text output;
public Text numText;
public Text cheking;
// Use this for initialization
public void Start () {
scor = 0;
score.text = "Score: " +scor.ToString();
numText.text ="The Number Is: " + “********”;
numb = Random.Range (90000000, 99999999);
guess = 3;
check.onClick.AddListener(lose);
gues.text = "Number Of Guess Is: " + guess.ToString ();
}
// Update is called once per frame
private void lose () {
string s = input1.text.ToString ();
string num = numb.ToString ();
int number = int.Parse (input1.text);
if (s.Length == num.Length) {
cheking.text = “Your Input Number Is OK .”;
if (guess != 0) {
for (int i = 0; i < s.Length; i++) {
if (s == num ) {
output.text = output.text + s ;
} else {
output.text = output.text + “*”;
scor += 5;
}
}
output.text = output.text + “\n”;
guess -= 1;
scor -= 5;
score.text = "Score: " +scor.ToString();
gues.text = "Number Of Guess Is: " + guess.ToString ();
if (numb == number) {
state.text = “You Win”;
numText.text ="The Number Is: " + num;
checkText.text = “reset”;
check.onClick.AddListener(reset);
}
else if (guess == 0) {
state.text = “You lose”;
numText.text ="The Number Is: " + num;
checkText.text = “reset”;
check.onClick.AddListener(reset);
}
}
} else {
cheking.text = “Check Your Input Number Length !!!”;
}
}
public void reset () {
score.text = "Final Score: " +scor.ToString();
output.text = “”;
state.text = “”;
guess = 3;
checkText.text = “check”;
numText.text ="The Number Is: " + “********”;
gues.text = "Number Of Guess Is: " + guess.ToString ();
check.onClick.AddListener(Start);
}
}




