Error FormatException: Input string was not in a correct format.
Error FormatException: Input string was not in a correct format. System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) (at :0) System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at :0) System.Int32.Parse (System.String s) (at :0) RandimNumber+d__16.MoveNext () (at Assets/Scripts/RandimNumber.cs:168) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0)
How I do that?
public class RandimNumber : MonoBehaviour
{
public Text text;
public Text t;
public Text dontkey;
public Text getkey;
public int number;
int button;
int textnum;
int tnum;
float positionShow;
float positionNum;
float showtime;
float pausetime;
private bool keyuse;
private bool textuse;
void Start()
{
StartCoroutine(TimerWait());
showtime = 3;
pausetime = 0;
button = 99;
textuse = false;
positionShow = 380;
positionNum = 371.25f;
text.text = "";
dontkey.enabled = false;
textnum = 0;
tnum = 0;
}
// Update is called once per frame
void Update()
{
Debug.Log("Textnum"+textnum);
Debug.Log("Tnum"+tnum);
if (text.text.Length == 16)
{
SceneManager.LoadScene("RandimNumberMedium");
}
if (textuse == true)
{
Debug.Log("Textuseใช้ได้");
if (text.text.Length == t.text.Length)
{
if (textnum == tnum)
{
pausetime = 0;
button = 99;
StopAllCoroutines();
Debug.Log("StartCoroutine(TimerWait())");
StartCoroutine(TimerWait());
textuse = false;
}
if (textnum != tnum)
{
StopAllCoroutines();
Debug.Log("gameOver");
textuse = false;
keyuse = false;
}
}
if (text.text.Length < t.text.Length)
{
StopAllCoroutines();
Debug.Log("gameOver");
textuse = false;
keyuse = false;
}
}
if (keyuse == true)
{
StopCoroutine("DontKey");
getkey.enabled = true;
Debug.Log("Key useใช้ได้");
if (Input.GetKeyDown(KeyCode.Keypad0))
{
button = 0;
t.text = t.text + button.ToString();
textuse = true;
if (t.text.Length == 1)
{
t.transform.localPosition = new Vector3(positionShow, -160, 0);
}
if (t.text.Length > 1 && t.text.Length < 8)
{
t.transform.localPosition = new Vector3(positionShow -= 12.6f, -160, 0);
Debug.Log("- 15");
}
if (t.text.Length == 8)
{
t.text = t.text + "\n";
}
Debug.Log("T=" + t.text);
Debug.Log("button = 0");
}
if (Input.GetKeyDown(KeyCode.Keypad1))
{
button = 1;
t.text = t.text + button.ToString();
textuse = true;
if (t.text.Length == 1)
{
t.transform.localPosition = new Vector3(positionShow, -160, 0);
}
if (t.text.Length > 1 && t.text.Length < 8)
{
t.transform.localPosition = new Vector3(positionShow -= 12.6f, -160, 0);
Debug.Log("- 15");
}
if (t.text.Length ==8)
{
t.text = t.text + "\n";
}
Debug.Log("T=" + t.text);
Debug.Log("button = 1");
}
}
if (keyuse == false)
{
getkey.enabled = false;
Debug.Log("Key useใช้ไม่ได้");
if (Input.anyKeyDown)
{
StopCoroutine("DontKey");
StartCoroutine(Dontkey());
Debug.Log("StartCoroutine(Dontkey())");
}
}
}
IEnumerator TimerWait()
{
keyuse = false;
yield return new WaitForSeconds(0.1f);
text.enabled = true;
textuse = false;
t.text = "";
positionShow = 380;
number = Random.Range(0, 2);
text.enabled = true;
if (text.text.Length < 8)
{
text.transform.localPosition = new Vector3(positionNum -= 41.25f, -50, 0);
}
if (text.text.Length == 8)
{
text.fontSize = 150;
text.transform.localPosition = new Vector3(41.25f, 50, 0);
text.text = text.text + "\n";
}
text.text = text.text + number.ToString();
textnum = int.Parse(text.text); // <---- -----------------------------I think it's not work.
tnum = int.Parse(t.text); // <----------------------------------------I think it's not work.
Debug.Log("รอ3วิ");
yield return new WaitForSeconds(showtime);
text.enabled = false;
yield return new WaitForSeconds(pausetime);
keyuse = true;
}
IEnumerator Dontkey()
{
dontkey.enabled = true;
yield return new WaitForSeconds(0.1f);
dontkey.enabled = false;
}
}
Your answer
Follow this Question
Related Questions
error CS1041: Identifier expected 1 Answer
Developer Console problems..... (in-game console) 0 Answers
Find with string concatenation 0 Answers
Having trouble converting this int to string, can someone help? 0 Answers
How to get the active/loaded Scene then turn the name of it into a string? [C#] 1 Answer