【发布时间】:2020-08-23 20:03:31
【问题描述】:
在我的代码中,我将字符串值转换为浮点值。在我的代码中:guns - 数组(大小 = 5)和 Chargunsinformations - 字符串值。
guns[gunsNum] = float.Parse(ChargunsInformation);
Unity 给我一个错误:
FormatException:输入字符串的格式不正确。 System.Number.ParseSingle(System.String 值, System.Globalization.NumberStyles 选项, System.Globalization.NumberFormatInfo numfmt) (在 :0) System.Single.Parse (System.String s,System.Globalization.NumberStyles 样式, System.Globalization.NumberFormatInfo 信息)(在 :0) System.Single.Parse (System.String s,System.IFormatProvider 提供程序)(在 :0) System.Convert.ToSingle (System.String 值)(在 :0) StartOfAllScript.Update () (在 Assets/Scripts/Player 脚本/StartOfAllScript.cs:35)
请帮帮我。我试图解决这个问题 2 小时。
【问题讨论】:
-
ChargunsInformation的价值是什么?为什么要为这个问题添加p标签?你可以试试float.TryParse()而不是float.parse()
标签: c#