Unity中InputField 报错 FormatException: Input string was not in the correct format

摘要:
参考如下:https://stackoverflow.com/questions/8321514/input-string-was-not-in-a-correct-format由于项目要求,需要设置InputFiled的默认值,因此可能会遇到此错误。Internet上有不同的答案。上面的网站是我需要的if(int.Parse(numText.text)˃1000){return;}之前的代码

参考如下:  https://stackoverflow.com/questions/8321514/input-string-was-not-in-a-correct-format

因为项目需求,需要设置InputFiled的默认值,于是乎就遇到这个报错..在网上查找有不同答案,上述网站就是我所需要的

if (int.Parse(numText.text)>1000)
{
    return;
} 

  之前的代码是这个样子的..

The error means that the string you're trying to parse an integer from doesn't actually contain a valid integer.

It's extremely unlikely that the text boxes will contain a valid integer immediately when the form is created - which is where you're getting the integer values. It would make much more sense to update a and b in the button click events (in the same way that you are in the constructor). Also, check out the Int.TryParse method - it's much easier to use if the string might not actually contain an integer - it doesn't throw an exception so it's easier to recover from.

大神的描述如下..

我们要做的,就是使用它的Int.TryParse方法

更改之后如下:

int result = 0;
if (int.TryParse (numText.text, out result)) {
  if (int.Parse(numText.text)>1000)
  {
      return;
  }
}

  https://www.bilibili.com/video/av11587576  20分50秒左右讲解

免责声明:文章转载自《Unity中InputField 报错 FormatException: Input string was not in the correct format》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Linux 中C/C++ search path(头文件搜索路径)mac cocoapod安装过程下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

HP服务器设置iLO

HP Server Setting iLO Step 1.开机后出现界面-按F11进入BootMenu;2.选择GenericUSBBoot并输入;3.选择SystemConfiguration(系统配置)并按Enter键;4.选择iLO4ConfigurationUtility进入;5.选择NetworkOptions Enter将DHCPEnable设置...

POI设置边框

对单元格设置边框时,有上下左右位置之分,所以POI也准备了四个不同的方法。值说明BORDER_DASH_DOTdash-dotborderBORDER_DASH_DOT_DOTdash-dot-dotborderBORDER_DASHEDdashborderBORDER_DOTTEDdotborderhair-lineborderBORDER_DOUBLEd...

vsCode mongoDB插件 Azure Cosmos DB

安装完成后,要重启下vsCode会看到然后点击绿色的小按钮,选择MongoDB再输入MongoDB的连接地址。当然要先把本地的mongoDB数据库打开,cmd黑窗口输入mongod--dbpathxxxx打开本地数据库输入完成地址后,回车就可以连接到自己的MongoDB数据库了...

Fiddler断点应用

对于不需要修改的报文,我们可以手动完成发送,fiddler会把拦截的网页发送到服务器或者客户端,需要修改的报文,可以在Fiddler修改完成后,再选择转发。另外,我们也可以使用Fiddler的断点功能模拟网络中断场景,验证服务器超时,客户端的处理情况。Afterresponses:服务器响应之后,在fiddler将响应传回给客户端之前。...

说说接口封装

今天,我为同事封装了一个接口。当谈到接口封装时,有很多关于它的讨论。在很多情况下,说一个服务好,一个服务坏,实际上是在吐槽服务团队之外暴露的界面质量。无论哪种语言,抽象的封装接口都由一个函数名、几个参数和几个返回值组成。总之,参数不应该被封装……我们在内部尝试接口_Catch不会抛出异常,所有信息都将以错误代码的形式返回。就php而言,建议进行异常处理。...

如何下载Chrome离线版EXE安装文件和MSI版安装文件

对于Chrome的稳定版本(官方版本),您只需添加“?”在Chrome的“最终用户许可协议”页面上的链接之后?Standalone=1对于Beta版和开发版Chrome,只需记住以下地址:http://dl.google.com/chrome/install/{versionnumber}/crome_安装程序中的版本号。exe表示要下载的Chrome版本号...