{"id":268,"date":"2015-03-19T11:10:34","date_gmt":"2015-03-19T03:10:34","guid":{"rendered":"http:\/\/qxu1606620110.my3w.com\/?p=268"},"modified":"2016-10-11T09:35:51","modified_gmt":"2016-10-11T01:35:51","slug":"unity3d%e5%8a%a8%e4%bd%9c%e7%b1%bb%e6%b8%b8%e6%88%8f%e4%b8%ad%e4%b8%a4%e7%a7%8d%e7%9b%b8%e6%9c%ba%e6%8a%96%e5%8a%a8","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=268","title":{"rendered":"Unity3D\u52a8\u4f5c\u7c7b\u6e38\u620f\u4e2d\u4e24\u79cd\u76f8\u673a\u6296\u52a8"},"content":{"rendered":"<p style=\"text-align: center;\"><span style=\"color: #ff0000;\">\u8f6c\u81ea\uff1a<a href=\"http:\/\/vitalzhu.github.io\/2015\/01\/29\/Unity3D\/\" target=\"_blank\">http:\/\/vitalzhu.github.io\/2015\/01\/29\/Unity3D\/<\/a><\/span><\/p>\n<p>\u5728\u52a8\u4f5c\u7c7bRPG\u6e38\u620f\u4e2d\uff0c\u4e3a\u4e86\u4f53\u73b0\u89d2\u8272\u7684\u6280\u80fd\u548c\u589e\u52a0\u52a8\u4f5c\u6253\u51fb\u611f\uff0c\u6211\u4eec\u5e38\u5e38\u4f1a\u7ed9\u76f8\u673a\u6dfb\u52a0\u6296\u52a8\u6548\u679c\u6765\u914d\u5408\u7279\u6548\u505a\u4e00\u4e9b\u6280\u80fd\u6548\u679c\u3002<br \/>\n\u6211\u5728\u7f51\u4e0a\u641c\u4e86\u4e00\u4e0b\uff0c\u7136\u540e\u7ed3\u5408\u81ea\u5df1\u7684\u9879\u76ee\u603b\u7ed3\u4e00\u4e0b\uff0c\u5927\u6982\u5206\u4e24\u79cd\u6296\u52a8\uff0c<\/p>\n<h2 id=\"\u6309\u6b21\u6570\u6296\u52a8\">\u6309\u6b21\u6570\u6296\u52a8<\/h2>\n<p>\u6309\u6b21\u6570\u6296\u52a8\uff0c\u5c31\u662f\u8ba9\u76f8\u673a\u6296\u52a8\u56fa\u5b9a\u7684\u6b21\u6570\u3002\u4f46\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u6211\u4eec\u4e3a\u4e86\u9632\u6b62\u6296\u52a8\u6548\u679c\u8fc7\u4e8e\u751f\u786c\uff0c\u4e00\u822c\u4f1a\u7ed9\u4e00\u4e2a\u6b21\u6570\u7684\u8303\u56f4\uff0c\u7136\u540e\u968f\u673a\u751f\u6210\u6296\u52a8\u7684\u6b21\u6570\uff0c\u8fd9\u6837\u73a9\u5bb6\u5728\u73a9\u7684\u65f6\u5019\u5c31\u4e0d\u4f1a\u611f\u89c9\u5f88\u91cd\u590d\u3002<\/p>\n<pre class=\"lang:c# decode:true\">using UnityEngine;\r\nusing System.Collections;\r\n\r\npublic class ShakeCamera : MonoBehaviour {\r\n\r\npublic Camera curCamera;\r\n\r\nbool isCanShake = false;\r\n\r\nint shakeCount = 0;\r\nVector3 mCurPos;\/\/\u76f8\u673a\u7684\u521d\u59cb\u4f4d\u7f6e\r\nfloat radio = 0.2f;\r\n\r\n\/\/ Use this for initialization\r\nvoid Start () {\r\n    \/\/ShakeCameraWithCount ();\r\n}\r\n\r\n\/\/ Update is called once per frame\r\nvoid Update () {\r\n    if(isCanShake)\r\n    {\r\n\r\n    }\r\n    ShakeWithCount();\r\n}\r\n\r\nvoid OnGUI()\r\n{\r\n    if(GUI.Button(new Rect(0,0,100,40),\"ShakeWithCount\"))\r\n    {\r\n        ShakeCameraWithCount();\r\n    }\r\n}\r\n\r\npublic void ShakeCameraWithCount()\r\n{\r\n    mCurPos = curCamera.transform.position;\r\n    shakeCount = Random.Range (5,14);\r\n}\r\n\r\nvoid ShakeWithCount()\r\n{\r\n    if(shakeCount&gt;0)\r\n    {\r\n        shakeCount--;\r\n        float r = Random.Range(-radio,radio);\/\/\u968f\u673a\u7684\u9707\u52a8\u5e45\u5ea6\r\n        if(shakeCount == 0)\r\n        {\r\n            \/\/\u4fdd\u8bc1\u6700\u7ec8\u56de\u5f52\u5230\u539f\u59cb\u4f4d\u7f6e\r\n            curCamera.transform.position = mCurPos;\r\n        }\r\n        else\r\n        {\r\n            curCamera.transform.position = mCurPos + Vector3.one*r;\r\n        }\r\n\r\n    }\r\n}\r\n}<\/pre>\n<h2 id=\"\u6309\u65f6\u95f4\u6296\u52a8\">\u6309\u65f6\u95f4\u6296\u52a8<\/h2>\n<p>\u6309\u65f6\u95f4\u6296\u52a8\uff0c\u987e\u540d\u601d\u4e49\u5c31\u662f\u8ba9\u76f8\u673a\u5728\u7ed9\u5b9a\u65f6\u95f4\u5185\u4e00\u76f4\u6301\u7eed\u505a\u6296\u52a8\u6548\u679c\u3002\u6309\u65f6\u95f4\u6296\u52a8\u4e0d\u4ec5\u53ef\u4ee5\u7528\u4f5c\u6280\u80fd\u6548\u679c\uff0c\u800c\u4e14\u53ef\u4ee5\u7528\u6765\u6a21\u62df\u5730\u9707\uff0c\u5de8\u77f3\u843d\u4e0b\u7b49\u81ea\u7136\u6548\u679c\uff0c\u8fd9\u6837\u65e2\u53ef\u4ee5\u8282\u7701\u7f8e\u5de5\u7684\u5de5\u4f5c\u91cf\uff0c\u53c8\u80fd\u8282\u7701\u8d44\u6e90\uff0c\u800c\u4e14\u6548\u679c\u8fd8\u5f88\u771f\u5b9e\u3002<br \/>\n\u5168\u90e8\u4ee3\u7801\u5c31\u4e0d\u53d1\u4e86\uff0c\u53ea\u53d1\u4e00\u90e8\u5206\u6838\u5fc3\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:c# decode:true\">void ShakeCamera_Time() \r\n{\r\n    if (shakeTime &gt; 0)\r\n    {\r\n        mainCamera.transform.position = mCurPos + Random.insideUnitSphere * radio;\r\n        shakeTime -= Time.deltaTime * deFactor;\r\n    }\r\n    else \r\n    {\r\n        shakeTime = 0;\r\n        \/\/mainCamera.transform.position = mCurPos;\r\n    }\r\n}<\/pre>\n<p>\u53ea\u8981\u653e\u5728Update\u91cc\u6267\u884c\uff0c\u7136\u540e\u4ece\u5916\u90e8\u4f20\u5165\u9707\u52a8\u7684\u65f6\u95f4\u5c31\u53ef\u4ee5\u770b\u5230\u6548\u679c\u5566\uff01<\/p>\n<p>\u5982\u679c\u6709\u66f4\u597d\u7684\u65b9\u6cd5\u6b22\u8fce\u8865\u5145(\u2299o\u2299)\u55ef\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81ea\uff1ahttp:\/\/vitalzhu.github.io\/2015\/01\/29\/ &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=268\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[67,68],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/268"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=268"}],"version-history":[{"count":4,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":769,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/268\/revisions\/769"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}