{"id":13671,"date":"2024-02-22T10:00:00","date_gmt":"2024-02-22T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=13671"},"modified":"2024-02-22T10:16:23","modified_gmt":"2024-02-22T01:16:23","slug":"unity%e7%90%83%e4%bd%93%e3%81%ae%e5%86%85%e5%81%b4%e3%81%ab%e8%a1%9d%e7%aa%81%e5%88%a4%e5%ae%9acollider%e3%82%92%e4%bb%98%e4%b8%8e%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/13671","title":{"rendered":"[Unity]\u7403\u4f53\u306e\u5185\u5074\u306b\u885d\u7a81\u5224\u5b9aCollider\u3092\u4ed8\u4e0e\u3059\u308b"},"content":{"rendered":"\n<p>360\u7403\u4f53\u753b\u50cf\u306e\u5185\u5074\u304b\u3089\u30a2\u30a4\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u3067\u8996\u7dda\u60c5\u5831\u3092\u8ffd\u5f93\u3057\u3066\u3069\u306e\u90e8\u5206\u3092\u898b\u3066\u3044\u305f\u304b\u30ed\u30b0\u3092\u53d6\u5f97\u3059\u308b\u51e6\u7406\u3092\u3064\u304f\u3063\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u30d3\u30eb\u30c9\u5f8c\u306b\u8996\u7dda\u306eRay\u3068360\u7403\u4f53\u753b\u50cf\u306e\u5185\u5074\u306e\u885d\u7a81\u5224\u5b9a\u304c\u3068\u308c\u306a\u304f\u306a\u308a\u30ed\u30b0\u306b\u51fa\u529b\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u554f\u984c\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002<br>\u4eca\u56de\u306f\u3053\u306e\u554f\u984c\u306e\u89e3\u6c7a\u65b9\u6cd5\u3092\u30b7\u30a7\u30a2\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br><\/p>\n\n\n\n<!--more-->\n\n\n\n<h2>\u7403\u4f53\u306e\u5185\u5074\u306b\u885d\u7a81\u5224\u5b9aCollider\u3092\u4ed8\u4e0e\u3059\u308b<\/h2>\n\n\n\n<p>Unity\u3067\u306f\u7403\u4f53\u306a\u3069\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u885d\u7a81\u5224\u5b9a\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5916\u5074\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br>\u306a\u306e\u3067\u307e\u305a\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u885d\u7a81\u5224\u5b9a\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5185\u5074\u306b\u5909\u66f4\u3059\u308b\u51e6\u7406\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u306eUnity\u30d5\u30a9\u30fc\u30e9\u30e0\u306e\u30b9\u30ec\u30c3\u30c9\u3067\u65b9\u6cd5\u304c\u7d39\u4ecb\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u3002<br><a href=\"https:\/\/forum.unity.com\/threads\/can-you-invert-a-sphere-or-box-collider.118733\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/forum.unity.com\/threads\/can-you-invert-a-sphere-or-box-collider.118733\/<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using UnityEngine;\nusing System.Linq;\nusing System.Collections;\n\npublic class AddInvertedMeshCollider : MonoBehaviour\n{\n\n    public bool removeExistingColliders = true;\n\n    public void CreateInvertedMeshCollider()\n    {\n        if (removeExistingColliders)\n            RemoveExistingColliders();\n\n        InvertMesh();\n\n        gameObject.AddComponent&lt;MeshCollider&gt;();\n    }\n\n    private void RemoveExistingColliders()\n    {\n        Collider&#091;] colliders = GetComponents&lt;Collider&gt;();\n        for (int i = 0; i &lt; colliders.Length; i++)\n            DestroyImmediate(colliders&#091;i]);\n    }\n\n    private void InvertMesh()\n    {\n        Mesh mesh = GetComponent&lt;MeshFilter&gt;().mesh;\n        mesh.triangles = mesh.triangles.Reverse().ToArray();\n    }\n}<\/code><\/pre>\n\n\n\n<p><br>\u3053\u306e\u65b9\u6cd5\u3067\u306f\u3001Unity\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4e0a\u3067\u30c7\u30d0\u30c3\u30b0\u30e2\u30fc\u30c9\u3068\u3057\u3066\u5b9f\u884c\u3057\u305f\u5834\u5408\u306f\u52d5\u4f5c\u3059\u308b\u306e\u3067\u3059\u304c\u3001exe\u3067\u30d3\u30eb\u30c9\u3057\u305f\u5f8c\u306f\u6b63\u3057\u304f\u52d5\u4f5c\u3057\u306a\u3044(\u5185\u5074\u306b\u885d\u7a81\u5224\u5b9aCollider\u304c\u4ed8\u4e0e\u3055\u308c\u306a\u3044)\u554f\u984c\u304c\u3042\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2>\u554f\u984c\u5207\u308a\u5206\u3051\u3068\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210<\/h2>\n\n\n\n<p>\u5f53\u521d\u306fexe\u3067\u30d3\u30eb\u30c9\u3057\u305f\u5f8c\u306b\u6b63\u3057\u304f\u52d5\u4f5c\u3057\u306a\u3044\u554f\u984c\u306e\u539f\u56e0\u306f\u30a2\u30a4\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u306b\u3042\u308b\u3068\u601d\u3044\u8abf\u67fb\u3092\u304a\u3053\u306a\u3063\u3066\u307e\u3057\u305f\u304c\u3001\u554f\u984c\u306e\u5207\u308a\u5206\u3051\u7528\u306b\u30a2\u30a4\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u3092\u4f7f\u7528\u3057\u306a\u3044\u30b7\u30f3\u30d7\u30eb\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3066\u78ba\u8a8d\u3092\u304a\u3053\u306a\u3063\u305f\u3068\u3053\u308d\u3001\u539f\u56e0\u306f\u4e0a\u8a18\u306eAddInvertedMeshCollider\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u30d3\u30eb\u30c9\u5f8c\u306b\u52d5\u4f5c\u3057\u306a\u304f\u306a\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u3002<br>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b7\u30f3\u30d7\u30eb\u306a\u30c6\u30b9\u30c8\u7528\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\u3092\u304a\u3053\u306a\u3044\u52d5\u4f5c\u78ba\u8a8d\u3092\u304a\u3053\u306a\u3044\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<ul><li>1. \u5916\u5468\u7528\u306e\u7403\u4f53\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/li><li>2. \u5916\u5468\u7528\u306e\u7403\u4f53\u306e\u5185\u5074\u306b\u52d5\u4f5c\u78ba\u8a8d\u7528\u306bUnity\u7269\u7406\u6f14\u7b97\u306e\u91cd\u529b\u8a2d\u5b9a\u3092\u304a\u3053\u306a\u3063\u305f\u5c0f\u3055\u306a\u7403\u4f53\u3092\u3044\u304f\u3064\u304b\u914d\u7f6e\u3057\u307e\u3059\u3002<\/li><li>3. \u5916\u5468\u7528\u306e\u7403\u4f53\u306e\u885d\u7a81\u5224\u5b9a\u304c\u5916\u5074\u306b\u3042\u308b\u304b\u5185\u5074\u306b\u3042\u308b\u304b\u3067\u5185\u5074\u306b\u914d\u7f6e\u3057\u305f\u5c0f\u3055\u306a\u7403\u4f53\u306e\u6319\u52d5\u304c\u5909\u308f\u308b\u306e\u3067\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u52d5\u4f5c\u3057\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/li><\/ul>\n\n\n\n<h4>\u5916\u5468\u7528\u306e\u7403\u4f53\u306e\u885d\u7a81\u5224\u5b9a\u304c\u300c\u5916\u5074\u300d\u306b\u3042\u308b\u5834\u5408\u3001<br>\u7403\u4f53\u306e\u5185\u5074\u306b\u3042\u308b\u5c0f\u3055\u306a\u7403\u4f53\u304c\u5916\u306b\u62bc\u3057\u51fa\u3055\u308c\u305d\u306e\u307e\u307e\u4e0b\u306b\u843d\u4e0b\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/h4>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"640\" height=\"328\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2024\/02\/1-2.gif\" alt=\"\" class=\"wp-image-13680\" \/><\/figure>\n\n\n\n<h4>\u5916\u5468\u7528\u306e\u7403\u4f53\u306e\u885d\u7a81\u5224\u5b9a\u304c\u300c\u5185\u5074\u300d\u306b\u3042\u308b\u5834\u5408\u3001<br>\u7403\u4f53\u306e\u5185\u5074\u306b\u3042\u308b\u5c0f\u3055\u306a\u7403\u4f53\u304c\u5916\u5468\u7528\u306e\u7403\u4f53\u306e\u5185\u5074\u306e\u885d\u7a81\u5224\u5b9a\u307e\u3067\u843d\u4e0b\u3057\u3066\u8df3\u306d\u304b\u3048\u308a\u307e\u3059\u3002<\/h4>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"640\" height=\"328\" src=\"https:\/\/www.gigas-jp.com\/appnews\/wp-content\/uploads\/sites\/4\/2024\/02\/2-2.gif\" alt=\"\" class=\"wp-image-13683\" \/><\/figure>\n\n\n\n<h2>Mesh Collider\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u8ffd\u52a0\u3057\u3066\u5bfe\u51e6\u3059\u308b<\/h2>\n\n\n\n<p>\u4e0a\u8a18\u306e\u554f\u984c\u3092\u6539\u5584\u3059\u308b\u305f\u3081\u306b\u5225\u306e\u65b9\u6cd5\u3092\u8abf\u3079\u3066\u3044\u305f\u3068\u3053\u308d\u3001\u4ee5\u4e0b\u306eQiita\u3067\u7d39\u4ecb\u3055\u308c\u3066\u3044\u305f\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3057\u305f\u3002<br><a href=\"https:\/\/qiita.com\/mechamogera\/items\/166f7486323e171356b4\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/qiita.com\/mechamogera\/items\/166f7486323e171356b4<\/a><\/p>\n\n\n\n<p>\u3053\u306e\u65b9\u6cd5\u3067\u306f\u5bfe\u8c61\u306e\u7403\u4f53\u306bMesh Collider\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u8ffd\u52a0\u3057\u305f\u4e0a\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u51e6\u7406\u3092\u3059\u308b\u624b\u6cd5\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class ReverseNormals2 : MonoBehaviour {\n\n    \/\/ Use this for initialization\n    void Start()\n    {\n        MeshFilter filter = GetComponent(typeof(MeshFilter)) as MeshFilter;\n        if (filter != null)\n        {\n            Mesh mesh = CopyMesh(filter.mesh);\n\n            Vector3&#091;] normals = mesh.normals;\n            for (int i = 0; i &lt; normals.Length; i++)\n                normals&#091;i] = -normals&#091;i];\n            mesh.normals = normals;\n\n            for (int m = 0; m &lt; mesh.subMeshCount; m++)\n            {\n                int&#091;] triangles = mesh.GetTriangles(m);\n                for (int i = 0; i &lt; triangles.Length; i += 3)\n                {\n                    int temp = triangles&#091;i + 0];\n                    triangles&#091;i + 0] = triangles&#091;i + 1];\n                    triangles&#091;i + 1] = temp;\n                }\n                mesh.SetTriangles(triangles, m);\n            }\n        }\n\n        this.GetComponent&lt;MeshCollider&gt;().sharedMesh = filter.mesh;\n    }\n\n    \/\/ Update is called once per frame\n    void Update () {\n\n    }\n\n    public Mesh CopyMesh(Mesh mesh)\n    {\n        var copy = new Mesh();\n        foreach (var property in typeof(Mesh).GetProperties())\n        {\n            if (property.GetSetMethod() != null &amp;&amp; property.GetGetMethod() != null)\n                {\n                property.SetValue(copy, property.GetValue(mesh, null), null);\n            }\n        }\n        return copy;\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><br>\u3053\u3061\u3089\u306e\u65b9\u6cd5\u3067\u306f\u30d3\u30eb\u30c9\u5f8c\u3082\u554f\u984c\u306a\u304f\u52d5\u4f5c\u3059\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p><br>\u6728\u66dc\u65e5\u62c5\u5f53\uff1anishida<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/13671\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/13671\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"[Unity]\u7403\u4f53\u306e\u5185\u5074\u306b\u885d\u7a81\u5224\u5b9aCollider\u3092\u4ed8\u4e0e\u3059\u308b\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/13671\" data-text=\"[Unity]\u7403\u4f53\u306e\u5185\u5074\u306b\u885d\u7a81\u5224\u5b9aCollider\u3092\u4ed8\u4e0e\u3059\u308b\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/13671\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/13671\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>360\u7403\u4f53\u753b\u50cf\u306e\u5185\u5074\u304b\u3089\u30a2\u30a4\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u3067\u8996\u7dda\u60c5\u5831\u3092\u8ffd\u5f93\u3057\u3066\u3069\u306e\u90e8\u5206\u3092\u898b\u3066\u3044\u305f\u304b\u30ed\u30b0\u3092\u53d6\u5f97\u3059\u308b\u51e6\u7406\u3092\u3064\u304f\u3063\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u30d3\u30eb\u30c9\u5f8c\u306b\u8996\u7dda\u306eRay\u3068360\u7403\u4f53\u753b\u50cf\u306e\u5185\u5074\u306e\u885d\u7a81\u5224\u5b9a\u304c\u3068\u308c\u306a\u304f\u306a\u308a\u30ed\u30b0\u306b\u51fa\u529b\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u554f\u984c\u304c\u767a [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100,109],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/13671"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=13671"}],"version-history":[{"count":14,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/13671\/revisions"}],"predecessor-version":[{"id":13691,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/13671\/revisions\/13691"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=13671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=13671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=13671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}