{"id":639,"date":"2019-11-01T16:32:54","date_gmt":"2019-11-01T08:32:54","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=639"},"modified":"2019-11-02T22:36:27","modified_gmt":"2019-11-02T14:36:27","slug":"unitywaitforsecondsfloat-nan%e7%9a%84%e5%bc%82%e5%b8%b8%e8%a1%8c%e4%b8%ba","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=639","title":{"rendered":"[Unity]WaitForSeconds(float.NaN)\u7684\u5f02\u5e38\u8868\u73b0"},"content":{"rendered":"\n<p>\u8bb0Unity2018.4\u534f\u7a0bCoroutine\u7684WaitForSeconds(float.Nan)\u7684\u5f02\u5e38\u8868\u73b0<\/p>\n\n\n\n<p>\u4e00\u3001\u5f02\u5e38\u534f\u7a0b\u4f53\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ExceptionCorout : MonoBehaviour\n{\n    IEnumerator WaitTask()\n    {\n        var c = 1.0f;\n        var d = c - c;\n        var f = 0 \/ d;\n        yield return new WaitForSeconds(f);\n    }\n    void Start()\n    {\n        StartCoroutine(WaitTask());\n    }\n    public static void Execute()\n    {\n        GameObject go = new GameObject(\"go\");\n        go.AddComponent&lt;ExceptionCorout>();\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u4ee3\u7801\u6267\u884c\u5fc5\u62a5\u9519<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float.NaN has been passed into WaitForSeconds which will result in an infinite wait time.\nUnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)\n&lt;Fire>c__Iterator1:MoveNext() (at Assets\/ExceptionCorout.cs:20)\nUnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u540e\u7eed\u521b\u5efa\u7684\u811a\u672c\uff0c\u5747\u4e0d\u518d\u6267\u884cStart()\u51fd\u6570\u4f53<\/p>\n\n\n\n<p>\u4e94\u3001\u7ed3\u8bba<br>WaitForSeconds\uff0c\u4f20\u5165\u65e0\u6548Nan\u53c2\u6570\uff0c\u4f1a\u5835\u4f4f\u6574\u4e2a\u534f\u7a0b\u7cfb\u7edf<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bb0Unity2018.4\u534f\u7a0bCoroutine\u7684WaitForSeconds(float.Nan)\u7684\u5f02\u5e38\u8868\u73b0  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[18],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/639"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=639"}],"version-history":[{"count":7,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/639\/revisions"}],"predecessor-version":[{"id":647,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/639\/revisions\/647"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}