{"id":642,"date":"2016-10-08T16:41:51","date_gmt":"2016-10-08T08:41:51","guid":{"rendered":"http:\/\/39.100.100.179\/?p=642"},"modified":"2016-10-11T09:26:14","modified_gmt":"2016-10-11T01:26:14","slug":"%e4%bd%bf%e7%94%a8%e4%bb%a3%e7%a0%81%e7%bb%99%e7%89%a9%e4%bd%93%e5%bc%ba%e5%88%b6%e5%8a%a0%e7%bb%84%e4%bb%b6","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=642","title":{"rendered":"RequireComponent\u7ed9\u7269\u4f53\u5f3a\u5236\u52a0\u7ec4\u4ef6"},"content":{"rendered":"<p>RequireComponent\u7684\u4f7f\u7528\uff1a<\/p>\n<p>\u5f53\u4f60\u6dfb\u52a0\u7684\u4e00\u4e2a\u7528\u4e86RequireComponent\u7ec4\u4ef6\u7684\u811a\u672c\uff0c\u9700\u8981\u7684\u7ec4\u4ef6\u5c06\u4f1a\u81ea\u52a8\u88ab\u6dfb\u52a0\u5230game object\uff08\u6e38\u620f\u7269\u4f53\uff09\u3002\u8fd9\u4e2a\u53ef\u4ee5\u6709\u6548\u7684\u907f\u514d\u7ec4\u4ef6\u9519\u8bef\u3002\u4e3e\u4e2a\u4f8b\u5b50\u4e00\u4e2a\u811a\u672c\u53ef\u80fd\u9700\u8981\u521a\u4f53\u603b\u662f\u88ab\u6dfb\u52a0\u5728\u76f8\u540c\u7684game object\uff08\u6e38\u620f\u7269\u4f53\uff09\u4e0a\u3002\u7528RequireComponent\u5c5e\u6027\u7684\u8bdd\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5c06\u88ab\u81ea\u52a8\u5b8c\u6210\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u6c38\u8fdc\u4e0d\u4f1a\u72af\u7ec4\u88c5\u9519\u8bef\u3002<\/p>\n<p>\u7528\u6cd5\uff1a\u5728\u65b0\u5efa\u7684\u7c7b\u524d\u9762\u52a0 [RequireComponent(typeof(Rigidbody))]<\/p>\n<p>\u5982\u56fe\uff1a\u4f7f\u7528\u524d\u00a0\u4f7f\u7528\u540e\uff0c\u800c\u4e14\u65b0\u52a0\u7684Rigidbody\u662f\u4e0d\u53ef\u4ee5\u88ab\u5220\u9664\u7684<\/p>\n<pre class=\"lang:c# decode:true \">using UnityEngine;\r\n\r\n\/\/ PlayerScript requires the GameObject to have a Rigidbody component\r\n[RequireComponent(typeof(Rigidbody))]\r\npublic class Test : MonoBehaviour\r\n{\r\n    Rigidbody rb;\r\n\r\n    void Start()\r\n    {\r\n        rb = GetComponent&lt;Rigidbody&gt;();\r\n    }\r\n    void FixedUpdate()\r\n    {\r\n        rb.AddForce(Vector3.up);\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>RequireComponent\u7684\u4f7f\u7528\uff1a \u5f53\u4f60\u6dfb\u52a0\u7684\u4e00\u4e2a\u7528\u4e86RequireCom &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=642\">\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":[23],"tags":[181],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/642"}],"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=642"}],"version-history":[{"count":3,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/642\/revisions"}],"predecessor-version":[{"id":706,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/642\/revisions\/706"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=642"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}