{"id":3885,"date":"2022-11-16T06:32:36","date_gmt":"2022-11-15T21:32:36","guid":{"rendered":"https:\/\/alaki.co.jp\/blog\/?p=3885"},"modified":"2022-11-16T06:32:36","modified_gmt":"2022-11-15T21:32:36","slug":"%e3%80%90unity%e3%80%91raycast%e3%81%a72d%e8%a6%81%e7%b4%a0%e3%82%92%e3%82%bf%e3%83%83%e3%83%97%e5%88%a4%e5%ae%9a%e3%81%99%e3%82%8b%e3%80%90raycasthit2d-boxcollider2d%e3%80%91","status":"publish","type":"post","link":"http:\/\/test.alaki.co.jp\/blog\/?p=3885","title":{"rendered":"\u3010Unity\u3011Raycast\u30672D\u8981\u7d20\u3092\u30bf\u30c3\u30d7\u5224\u5b9a\u3059\u308b\u3010RaycastHit2D + BoxCollider2D\u3011"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01<br \/>\nXR\u30af\u30ea\u30a8\u30a4\u30bf\u30fc\u306e\u4f0a\u6771\uff08<a href=\"https:\/\/twitter.com\/ALAKIWebVRAR1\" target=\"_blank\">@ALAKIWebVRAR1<\/a>\uff09\u3067\u3059\u3002<\/p>\n<p>\u203bTwitter\u3067\u3082AR\/VR\u306e\u4e8b\u3092\u4e2d\u5fc3\u306b\u60c5\u5831\u767a\u4fe1\u4e2d\u3067\u3059\u3002<br \/>\n\u3088\u304b\u3063\u305f\u3089\u30d5\u30a9\u30ed\u30fc\u304a\u9858\u3044\u3057\u307e\u3059\uff01<br \/>\n<a class=\"twitter-follow-button\" href=\"https:\/\/twitter.com\/ALAKIWebVRAR1?ref_src=twsrc%5Etfw\" data-show-count=\"false\">Follow @ALAKIWebVRAR1<\/a><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<p>\u4eca\u56de\u306f\u3001Unity\u30672D\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30bf\u30c3\u30d7\u5224\u5b9a\u3059\u308b\u65b9\u6cd5\u3092\u5099\u5fd8\u9332\u7684\u306b\u307e\u3068\u3081\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u307e\u305a\u306f\u3001\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3093\u3067\u4f55\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u304b\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u5b9f\u88c5\u3057\u305f\u3044\u3053\u3068<\/h2>\n<p>\u5148\u306b\u30b4\u30fc\u30eb\u304b\u3089\u304a\u898b\u305b\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/ray_2d_1.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3896\" src=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/ray_2d_1.gif\" alt=\"ray_2d_1\" width=\"400\" height=\"546\" \/><\/a><\/p>\n<p>\u30b7\u30fc\u30f3\u306b\u914d\u7f6e\u3057\u305fUI Text\u304c\u30de\u30a6\u30b9\u3067\u30c9\u30e9\u30c3\u30b0\u3057\u305f\u6642\u306b\u8ffd\u5f93\u3059\u308b\u3088\u3046\u306a\u52d5\u304d\u3067\u3059\uff01<br \/>\n\u30b7\u30f3\u30d7\u30eb\u306a\u30a4\u30f3\u30bf\u30e9\u30af\u30b7\u30e7\u30f3\u3067\u3059\u304c\u3001\u3055\u307e\u3056\u307e\u306a\u30c6\u30af\u30cb\u30c3\u30af\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u9806\u3092\u8ffd\u3063\u3066\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u30b7\u30fc\u30f3\u3092\u898b\u3066\u307f\u308b<\/h2>\n<p>\u307e\u305a\u306f\u30b7\u30fc\u30f3\u306e\u69cb\u6210\u3092\u898b\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/8cfc09c04cf121a272a7313fe27796de.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3890\" src=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/8cfc09c04cf121a272a7313fe27796de.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2022-11-15 20.15.31\" width=\"328\" height=\"192\" srcset=\"http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/8cfc09c04cf121a272a7313fe27796de.png 328w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/8cfc09c04cf121a272a7313fe27796de-300x176.png 300w\" sizes=\"(max-width: 328px) 100vw, 328px\" \/><\/a><\/p>\n<p>\u30ab\u30e1\u30e9\u3068\u3001\u6700\u4f4e\u9650\u306e\u30e9\u30a4\u30c8\u3001\u30ad\u30e3\u30f3\u30d0\u30b9\u3068TextMeshPro\u3067\u4f5c\u3063\u305f\u30c6\u30ad\u30b9\u30c8UI\u304c2\u3064\u3068\u3044\u3046\u30b7\u30f3\u30d7\u30eb\u306a\u30b7\u30fc\u30f3\u3067\u3059\u3002<\/p>\n<p>\u30dd\u30a4\u30f3\u30c8\u306f\u3001Canvas\u306eRenderMode\u304c\u300cWorld Space\u300d\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/e9cb1135a27066e2cea8796cd512883c.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-3891\" src=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/e9cb1135a27066e2cea8796cd512883c-571x1024.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2022-11-15 20.15.45\" width=\"571\" height=\"1024\" srcset=\"http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/e9cb1135a27066e2cea8796cd512883c-571x1024.png 571w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/e9cb1135a27066e2cea8796cd512883c-167x300.png 167w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/e9cb1135a27066e2cea8796cd512883c-768x1376.png 768w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/e9cb1135a27066e2cea8796cd512883c.png 788w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><\/p>\n<p>\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u3067\u306f\u306a\u304f\u3001\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u7cfb\u306b2D\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u914d\u7f6e\u3057\u3066\u3044\u308b\u5f62\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u4e0a\u3067\u3001\u753b\u9762\u4e0a\u306e\u30bf\u30c3\u30d7\u3092\u691c\u77e5\u3057\u3066\u3001\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u7cfb\u306b\u3042\u308b2D\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30de\u30a6\u30b9\u306b\u8ffd\u5f93\u3055\u305b\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u4eca\u56de\u306e\u30b4\u30fc\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30de\u30a6\u30b9\u306e\u5ea7\u6a19\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u307e\u305a\u306f\u30de\u30a6\u30b9\u30af\u30ea\u30c3\u30af\u3092\u691c\u77e5\u3057\u3066\u3001\u5ea7\u6a19\u3092\u53d6\u5f97\u3059\u308b\u3068\u3053\u308d\u304b\u3089\u30b9\u30bf\u30fc\u30c8\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u9069\u5f53\u306a\u540d\u524d\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7528\u610f\u3057\u3066\u3001\u30c6\u30ad\u30b9\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30a2\u30bf\u30c3\u30c1\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/cece7aacf34ed182b3c61c5d523525e0.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3892\" src=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/cece7aacf34ed182b3c61c5d523525e0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2022-11-15 20.49.00\" width=\"778\" height=\"382\" srcset=\"http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/cece7aacf34ed182b3c61c5d523525e0.png 778w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/cece7aacf34ed182b3c61c5d523525e0-300x147.png 300w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/cece7aacf34ed182b3c61c5d523525e0-768x377.png 768w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/a><\/p>\n<p>\u4eca\u56de\u306f\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u540d\u524d\u3092\u300cDraggableUI\u300d\u3068\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001Update\u95a2\u6570\u306b\u3001\u30de\u30a6\u30b9\u30af\u30ea\u30c3\u30af\u3092\u5224\u5b9a\u3059\u308bif\u6587\u3068\u3001\u30af\u30ea\u30c3\u30af\u3057\u305f\u5834\u6240\u3092\u53d6\u5f97\u3057\u3066\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">using System.Collections;\r\nusing System.Collections.Generic;\r\nusing UnityEngine;\r\n\r\npublic class DraggableUI : MonoBehaviour\r\n{\r\n\r\n    \/\/ Start is called before the first frame update\r\n    void Start()\r\n    {\r\n    }\r\n\r\n    \/\/ Update is called once per frame\r\n    void Update()\r\n    {\r\n        \/* \u30de\u30a6\u30b9\u30af\u30ea\u30c3\u30af\u3092\u691c\u77e5 *\/\r\n        if (Input.GetMouseButton(0)) {\r\n\r\n            \/* \u30af\u30ea\u30c3\u30af\u5ea7\u6a19\uff08\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u7cfb\uff09 *\/\r\n            Debug.Log(Input.mousePosition);\r\n\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p><a href=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/41f4d131b7b025a803687f085e6ef04c.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3893\" src=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/41f4d131b7b025a803687f085e6ef04c.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2022-11-15 20.54.32\" width=\"634\" height=\"412\" srcset=\"http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/41f4d131b7b025a803687f085e6ef04c.png 634w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/41f4d131b7b025a803687f085e6ef04c-300x195.png 300w\" sizes=\"(max-width: 634px) 100vw, 634px\" \/><\/a><\/p>\n<p>\u30de\u30a6\u30b9\u5ea7\u6a19\u304c\u3068\u308c\u307e\u3057\u305f\uff01<\/p>\n<p>\u305f\u3060\u3057\u3001\u53d6\u5f97\u3067\u304d\u305f\u5ea7\u6a19\u306f\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6700\u7d42\u7684\u306b\u64cd\u4f5c\u3059\u308b\u30c6\u30ad\u30b9\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u5909\u63db\u3057\u3066\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u306d\u3002<\/p>\n<h2>\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u3068\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u306e\u5909\u63db<\/h2>\n<p>\u30af\u30ea\u30c3\u30af\u3057\u305f\u5834\u6240\u306e\u5ea7\u6a19\u3092\u3001\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u304b\u3089\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u306b\u5909\u63db\u3059\u308b\u305f\u3081\u306b\u3001\u300cScreenToWorldPoint\u300d\u3068\u3044\u3046\u30ab\u30e1\u30e9\u306b\u5099\u308f\u3063\u3066\u3044\u308b\u95a2\u6570\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">using System.Collections;\r\nusing System.Collections.Generic;\r\nusing UnityEngine;\r\n\r\npublic class DraggableUI : MonoBehaviour\r\n{\r\n\r\n    \/\/ Start is called before the first frame update\r\n    void Start()\r\n    {\r\n    }\r\n\r\n    \/\/ Update is called once per frame\r\n    void Update()\r\n    {\r\n        \/* \u30de\u30a6\u30b9\u30af\u30ea\u30c3\u30af\u3092\u691c\u77e5 *\/\r\n        if (Input.GetMouseButton(0)) {\r\n\r\n            \/* \u30af\u30ea\u30c3\u30af\u5ea7\u6a19\uff08\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u7cfb\uff09 *\/\r\n            Vector3 screenPos = Input.mousePosition;\r\n\r\n            \/* \u30af\u30ea\u30c3\u30af\u5ea7\u6a19\uff08\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u7cfb\uff09 *\/\r\n            Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos);\r\n\r\n        }\r\n    }\r\n}<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u30ab\u30e1\u30e9\u3092\u57fa\u6e96\u3068\u3057\u3066\u3001\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u3092\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30af\u30ea\u30c3\u30af\u5ea7\u6a19\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8ffd\u5f93\u3055\u305b\u308b<\/h2>\n<p>\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u304c\u53d6\u308c\u308c\u3070\u3001\u305d\u306e\u5ea7\u6a19\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30c8\u30e9\u30f3\u30b9\u30d5\u30a9\u30fc\u30e0\u306b\u6e21\u3057\u3066\u3042\u3052\u308c\u3070\u3001\u30de\u30a6\u30b9\u306b\u8ffd\u5f93\u3059\u308b\u51e6\u7406\u304c\u304b\u3051\u305d\u3046\u3067\u3059\u3002<br \/>\n\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true\">using System.Collections;\r\nusing System.Collections.Generic;\r\nusing UnityEngine;\r\n\r\npublic class DraggableUI : MonoBehaviour\r\n{\r\n\r\n    \/\/ Start is called before the first frame update\r\n    void Start()\r\n    {\r\n    }\r\n\r\n    \/\/ Update is called once per frame\r\n    void Update()\r\n    {\r\n        \/* \u30de\u30a6\u30b9\u30af\u30ea\u30c3\u30af\u3092\u691c\u77e5 *\/\r\n        if (Input.GetMouseButton(0)) {\r\n\r\n            \/* \u30af\u30ea\u30c3\u30af\u5ea7\u6a19\uff08\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u7cfb\uff09 *\/\r\n            Vector3 screenPos = Input.mousePosition;\r\n            screenPos.z = 1.0f;\r\n\r\n            \/* \u30af\u30ea\u30c3\u30af\u5ea7\u6a19\uff08\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u7cfb\uff09 *\/\r\n            Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos);\r\n\r\n            \/* \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30dd\u30b8\u30b7\u30e7\u30f3\u304b\u3089\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u7cfb\u307e\u3067\u306e\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3 *\/\r\n            transform.position = Vector3.Lerp(\r\n                    transform.position,\r\n                    worldPos,\r\n                    3.0f * Time.deltaTime);\r\n\r\n        }\r\n    }\r\n}<\/pre>\n<p>\u30dd\u30a4\u30f3\u30c8\u304c2\u3064\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>1\u3064\u76ee\u306f\u3001\u53d6\u5f97\u3057\u305f\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u306b\u5965\u884c\u304d\u3092\u4ed8\u4e0e\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\u3002<br \/>\n\u305d\u306e\u307e\u307e\u3067\u306fZ\u306e\u5024\u304c0\u306b\u306a\u308a\u3001\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u306b\u5909\u63db\u3057\u305f\u6642\u306b\u6bce\u56de\u540c\u3058Vector3\u306e\u5024\u304c\u8fd4\u3063\u3066\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\n\u610f\u56f3\u3057\u305f\u901a\u308a\u306e\u5024\u3092\u5f97\u308b\u305f\u3081\u306b\u3001Z\u306e\u5024\u306b\u4efb\u610f\u306e\u5024\u3092\u5165\u308c\u3066\u304b\u3089\u3001\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u3078\u306e\u5909\u63db\u3092\u884c\u3046\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>2\u3064\u76ee\u306f\u3001Lerp\u95a2\u6570\u3067\u3059\u3002Lerp\u95a2\u6570\u306f\u3001\u3042\u308b\u70b9\u304b\u3089\u3042\u308b\u70b9\u307e\u3067\u306e\u5024\u306e\u5909\u5316\u3092\u88dc\u5b8c\u3057\u3066\u3001\u5f90\u3005\u306b\u5909\u5316\u3059\u308b\u3088\u3046\u306a\u8868\u73fe\u3092\u53ef\u80fd\u306b\u3057\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306fLerp\u95a2\u6570\u306b3\u3064\u306e\u5f15\u6570\u3092\u6e21\u3057\u3066\u3044\u307e\u3059\u30021\u3064\u76ee\u306e\u5f15\u6570\u304c\u300c\u5909\u5316\u524d\u306e\u5024\u300d\u30012\u3064\u76ee\u306e\u5f15\u6570\u304c\u300c\u5909\u5316\u5f8c\u306e\u5024\u300d\u30013\u3064\u76ee\u306e\u5f15\u6570\u304c\u300c\u88dc\u5b8c\u5024\u300d\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067\u306e\u5185\u5bb9\u3067\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4f5c\u6210\u3057\u305f\u300cDraggableUI\u300d\u3068\u3044\u3046\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u3001\u30b7\u30fc\u30f3\u306b\u3042\u308b\u30c6\u30ad\u30b9\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30a2\u30bf\u30c3\u30c1\u3057\u3066\u304b\u3089\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/086a326115dda5bb44f4ab6d0a59d7f7.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3894\" src=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/086a326115dda5bb44f4ab6d0a59d7f7.gif\" alt=\"\u753b\u9762\u53ce\u9332-2022-11-15-21.06\" width=\"400\" height=\"546\" \/><\/a><\/p>\n<p>\u3060\u3044\u3076\u30b4\u30fc\u30eb\u306b\u8fd1\u3065\u3044\u3066\u304d\u307e\u3057\u305f\uff01<\/p>\n<p>\u304c\u3001\u30de\u30a6\u30b9\u3092\u30c9\u30e9\u30c3\u30b0\u3057\u305f\u77ac\u9593\u30012\u3064\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u4e00\u7dd2\u306b\u306a\u3063\u3066\u8ffd\u5f93\u3057\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u4fee\u6b63\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2>RaycastHit2D\u3092\u5b9f\u88c5<\/h2>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u90e8\u5206\u3092\u30c9\u30e9\u30c3\u30b0\u3057\u305f\u5834\u5408\u306e\u307f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30de\u30a6\u30b9\u306b\u8ffd\u5f93\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u306b\u306f\u3001\u30de\u30a6\u30b9\u3068\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u885d\u7a81\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u5224\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u308c\u3092\u5b9f\u73fe\u3059\u308b\u306e\u304c\u300cRaycast\u300d\u3068\u547c\u3070\u308c\u308b\u3082\u306e\u3067\u3059\u3002\u30af\u30ea\u30c3\u30af\u3057\u305f\u5ea7\u6a19\u4f4d\u7f6e\u304b\u3089\u3001\u5965\u5074\u306b\u5411\u304b\u3063\u3066\u4f38\u3073\u308b\u898b\u3048\u306a\u3044\u5149\u7dda\u3092\u4f38\u3070\u3057\u3001\u305d\u306e\u5149\u7dda\u306b\u3042\u305f\u3063\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3059\u308b\u3068\u3044\u3046\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">using System.Collections;\r\nusing System.Collections.Generic;\r\nusing UnityEngine;\r\n\r\npublic class DraggableUI : MonoBehaviour\r\n{\r\n\r\n    \/\/ Start is called before the first frame update\r\n    void Start()\r\n    {\r\n    }\r\n\r\n    \/\/ Update is called once per frame\r\n    void Update()\r\n    {\r\n        \/* \u30de\u30a6\u30b9\u30af\u30ea\u30c3\u30af\u3092\u691c\u77e5 *\/\r\n        if (Input.GetMouseButton(0)) {\r\n\r\n            \/\/ \u30bf\u30c3\u30d7\u3057\u305f\u5834\u6240\u304b\u3089Ray\u3092\u4f5c\u6210\r\n            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);\r\n\r\n            \/\/ Raycast\u3092\u4f5c\u6210\r\n            RaycastHit2D hit2d = Physics2D.Raycast((Vector2)ray.origin, (Vector2)ray.direction);\r\n\r\n            \/\/Ray\u304c\u4f55\u304b\u306b\u885d\u7a81\u3057\u305f\u3053\u3068\u3092\u691c\u77e5 &amp; \u885d\u7a81\u3057\u305f\u5bfe\u8c61\u304c\u81ea\u5206\u81ea\u8eab\u304b\u3092\u5224\u5225\r\n            if(hit2d &amp;&amp; hit2d.transform.gameObject == this.gameObject) {\r\n\r\n                \/* \u30af\u30ea\u30c3\u30af\u5ea7\u6a19\uff08\u30b9\u30af\u30ea\u30fc\u30f3\u5ea7\u6a19\u7cfb\uff09 *\/\r\n                Vector3 screenPos = Input.mousePosition;\r\n                screenPos.z =  1.0f;\r\n\r\n                \/* \u30af\u30ea\u30c3\u30af\u5ea7\u6a19\uff08\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u7cfb\uff09 *\/\r\n                Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos);\r\n\r\n                \/* \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30dd\u30b8\u30b7\u30e7\u30f3\u304b\u3089\u30ef\u30fc\u30eb\u30c9\u5ea7\u6a19\u7cfb\u307e\u3067\u306e\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3 *\/\r\n                transform.position = Vector3.Lerp(\r\n                        transform.position,\r\n                        worldPos,\r\n                        3.0f * Time.deltaTime);\r\n\r\n            }\r\n\r\n        }\r\n    }\r\n}<\/pre>\n<p>\u30ab\u30e1\u30e9\u304c\u6301\u3064\u300cScreenPointToRay\u300d\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u306b\u3001\u30af\u30ea\u30c3\u30af\u3057\u305f\u5834\u6240\u306e\u5ea7\u6a19\u3092\u6e21\u3057\u3001Ray(\u5149\u7dda)\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u6b21\u306b\u3001Physics2D.Raycast\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3067Ray\u304c\u5f53\u305f\u3063\u305f\u7269\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306eRaycastHit2D\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\nRaycastHit2D\u306fRaycast\u30922D\u8981\u7d20\u306b\u5bfe\u3057\u3066\u6271\u3046\u305f\u3081\u306e\u30af\u30e9\u30b9\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3001if\u6587\u306b2\u3064\u306e\u6761\u4ef6\u3092&amp;\u3067\u6e21\u3057\u3066\u3001if\u306e\u4e2d\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5ea7\u6a19\u3092\u66f8\u304d\u63db\u3048\u308b\u51e6\u7406\u3092\u79fb\u3057\u307e\u3057\u305f\u3002<br \/>\n\u6761\u4ef6\u306e1\u3064\u76ee\u306f\u3001RaycastHit2D\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5b58\u5728\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u307f\u3066\u3044\u307e\u3059\u3002<br \/>\n\u6761\u4ef6\u306e2\u3064\u76ee\u306f\u3001RaycastHit2D\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u691c\u77e5\u3057\u305f\u885d\u7a81\u3057\u305fGameObject\u304c\u3001\u81ea\u8eab\u306eGameObject\u3068\u4e00\u81f4\u3059\u308b\u304b\u3069\u3046\u304b\u3067\u3059\u3002<\/p>\n<h2>BoxCollider2D\u3092\u30a2\u30bf\u30c3\u30c1\u3059\u308b<\/h2>\n<p>\u3053\u3053\u307e\u3067\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u8a18\u8ff0\u306f\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002<br \/>\n\u3057\u304b\u3057\u3053\u306e\u307e\u307e\u3067\u5b9f\u884c\u3057\u3066\u3082\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3002<br \/>\n\u30c9\u30e9\u30c3\u30b0\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5074\u306b\u3001Ray\u304c\u3076\u3064\u304b\u308b\u305f\u3081\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u30a2\u30bf\u30c3\u30c1\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f2D\u7528\u306eRaycastHit2D\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u300cBoxCollider2D\u300d\u3068\u3044\u3046\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/9c0ad08fda179a74dff154bf89f60a89.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3897\" src=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/9c0ad08fda179a74dff154bf89f60a89.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2022-11-16 6.25.44\" width=\"764\" height=\"762\" srcset=\"http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/9c0ad08fda179a74dff154bf89f60a89.png 764w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/9c0ad08fda179a74dff154bf89f60a89-150x150.png 150w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/9c0ad08fda179a74dff154bf89f60a89-300x300.png 300w, http:\/\/test.alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/9c0ad08fda179a74dff154bf89f60a89-160x160.png 160w\" sizes=\"(max-width: 764px) 100vw, 764px\" \/><\/a><\/p>\n<p>\u30a2\u30bf\u30c3\u30c1\u3067\u304d\u305f\u3089\u3001\u300cSize\u300d\u306e\u90e8\u5206\u3092\u5b9f\u969b\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u5408\u308f\u305b\u3066\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067\u3067\u5168\u3066\u306e\u6e96\u5099\u304c\u6574\u3044\u307e\u3057\u305f\u3002<br \/>\n\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\uff01<\/p>\n<p><a href=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/ray_2d_1.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3896\" src=\"https:\/\/alaki.co.jp\/blog\/wp-content\/uploads\/2022\/11\/ray_2d_1.gif\" alt=\"ray_2d_1\" width=\"400\" height=\"546\" \/><\/a><\/p>\n<p>\u3067\u304d\u307e\u3057\u305f\u306d\uff01<\/p>\n<h2>\u6700\u5f8c\u306b<\/h2>\n<p>\u4eca\u56de\u3054\u7d39\u4ecb\u3057\u305f\u57fa\u672c\u7684\u306aRaycast\u306e\u5b9f\u88c5\u306f\u3001\u3055\u307e\u3056\u307e\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u6d3b\u7528\u3067\u304d\u308b\u3082\u306e\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u5f0a\u793e\u3067\u306f\u3001Unity\u3092\u306f\u3058\u3081\u3055\u307e\u3056\u307e\u306a\u6280\u8853\u3092\u6d3b\u7528\u3057\u3066\u3001\u3053\u308c\u304b\u3089\u3082\u4e16\u306e\u4e2d\u306b\u65b0\u3057\u3044\u4fa1\u5024\u3092\u3054\u63d0\u4f9b\u3057\u7d9a\u3051\u307e\u3059\u3002<\/p>\n<p>\u6700\u8fd1\u3067\u306f\u3001\u73fe\u5b9f\u306e\u3042\u3089\u3086\u308b\u5834\u6240\u304b\u3089\u30c7\u30b8\u30bf\u30eb\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u8ab0\u3067\u3082AR\u7a7a\u9593\u306b\u30c9\u30ed\u30c3\u30d7\u3067\u304d\u308b\u300cMUGHEN\u300d\u3068\u3044\u3046\u30a2\u30d7\u30ea\u3092\u30ea\u30ea\u30fc\u30b9\u3057\u307e\u3057\u305f\u3002\u305c\u3072\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u305f\u3060\u304d\u3001\u73fe\u5b9f\u3092\u62e1\u5f35\u3059\u308b\u611f\u899a\u3092\u4f53\u9a13\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n<p>\u25a0MUGHEN \u30b5\u30fc\u30d3\u30b9\u7d39\u4ecb\u30b5\u30a4\u30c8<br \/>\n<a href=\"https:\/\/alaki.co.jp\/lp\/mughen\/\" target=\"_blank\">https:\/\/alaki.co.jp\/lp\/mughen\/<\/a><\/p>\n<p>\u307e\u305f\u3001\u304a\u5ba2\u3055\u307e\u304b\u3089\u3054\u76f8\u8ac7\u3092\u3044\u305f\u3060\u304d\u3001\u65e5\u672c\u5404\u5730\u3067AR\u3092\u4f7f\u3063\u305f\u30ef\u30af\u30ef\u30af\u3059\u308b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30ea\u30ea\u30fc\u30b9\u3057\u3066\u307e\u3044\u308a\u307e\u3057\u305f\u3002<br \/>\nAR\u306e\u30d1\u30a4\u30aa\u30cb\u30a2\u3068\u3057\u3066\u3001\u9ad8\u3044\u6280\u8853\u529b\u3068\u30d3\u30b8\u30cd\u30b9\u63d0\u6848\u304c\u53ef\u80fd\u3067\u3059\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30b5\u30a4\u30c8\u3088\u308a\u304a\u6c17\u8efd\u306b\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\uff01<\/p>\n<p>\u25a0WebAR\u958b\u767a \u7279\u8a2d\u30b5\u30a4\u30c8<br \/>\n<a href=\"https:\/\/alaki.co.jp\/lp\/webar\/\" target=\"_blank\">https:\/\/alaki.co.jp\/lp\/webar\/<\/a><\/p>\n<p>ALAKI\u682a\u5f0f\u4f1a\u793e\u3067\u306f\u3001\u300cMUGHEN\u300d\u3092\u306f\u3058\u3081\u3068\u3059\u308b\u6700\u5148\u7aef\u6280\u8853\u3092\u4f7f\u3063\u3066\u4e16\u306e\u4e2d\u306b\u4fa1\u5024\u3092\u63d0\u4f9b\u3059\u308b\u305f\u3081\u3001\u4e00\u7dd2\u306b\u5927\u304d\u306a\u76ee\u6a19\u306b\u6311\u6226\u3059\u308b\u4ef2\u9593\u3092\u52df\u96c6\u4e2d\u3067\u3059\uff01\u8208\u5473\u306e\u3042\u308b\u65b9\u306f\u3001\u4ee5\u4e0b\u306e\u30ea\u30f3\u30af\u304b\u3089\u3054\u5fdc\u52df\u304f\u3060\u3055\u3044\uff01<\/p>\n<p>\u25a0ALAKI \u30ea\u30af\u30eb\u30fc\u30c8\u30b5\u30a4\u30c8<br \/>\n<a href=\"https:\/\/recruit.alaki.co.jp\/\" target=\"_blank\">https:\/\/recruit.alaki.co.jp\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01 XR\u30af\u30ea\u30a8\u30a4\u30bf\u30fc\u306e\u4f0a\u6771\uff08@ALAKIWebVRAR1\uff09&#46;&#46;&#46;<\/p>\n","protected":false},"author":8,"featured_media":3896,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[32,16],"tags":[39],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3885"}],"collection":[{"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3885"}],"version-history":[{"count":3,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3885\/revisions"}],"predecessor-version":[{"id":3898,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3885\/revisions\/3898"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/media\/3896"}],"wp:attachment":[{"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3885"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/test.alaki.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}