{"id":14340,"date":"2023-12-09T21:51:14","date_gmt":"2023-12-09T12:51:14","guid":{"rendered":"http:\/\/www.tyosuke20xx.com\/blog\/?p=14340"},"modified":"2023-12-09T21:51:16","modified_gmt":"2023-12-09T12:51:16","slug":"c-%e3%81%8a%e3%81%ab%e3%82%83%e3%82%93%e3%81%93%e5%a4%a7%e6%88%a6%e4%ba%89","status":"publish","type":"post","link":"http:\/\/www.tyosuke20xx.com\/blog\/?p=14340","title":{"rendered":"C# \u304a\u306b\u3083\u3093\u3053\u5927\u6226\u4e89"},"content":{"rendered":"\n<p>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<\/p>\n\n\n\n<p>public class CharactorMove : MonoBehaviour<br>{<br>public enum TYPE<br>{<br>PLAYER,<br>ENEMY,<br>}<br>public TYPE type = TYPE.PLAYER;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float direction;\nVector3 pos;\n\nbool isMove = true;\n\n\/\/ Start is called before the first frame update\nvoid Start()\n{\n    switch(type)\n    {\n        case TYPE.PLAYER:\n            \/\/Player\u6642\u306e\u51e6\u7406\n            direction = -1;\n            break;\n        case TYPE.ENEMY:\n            \/\/Enemy\u306e\u6642\u306e\u51e6\u7406\n            direction = 1;\n            break;\n    }\n    pos = new Vector3(direction, 0, 0);\n}\n\n\/\/ Update is called once per frame\nvoid Update()\n{\n    if(isMove)\n    {\n        transform.position += pos * Time.deltaTime;\n    }\n}\nprivate void OnTriggerEnter2D(Collider2D collision)\n{\n    \/\/\u6575\u306b\u3076\u3064\u304b\u3063\u305f\u3089\u79fb\u52d5\u3068\u3081\u308b\n    if(collision.gameObject.tag == \"Enemy\" &amp;&amp; type == TYPE.PLAYER\n        || collision.gameObject.tag == \"Player\" &amp;&amp; type == TYPE.ENEMY)\n    {\n        isMove = false;\n    }\n    \/\/\u653b\u6483\u3092\u3057\u306f\u3058\u3081\u308b\n}\nprivate void OnTriggerExit2D(Collider2D collision)\n{\n    if (collision.gameObject.tag == \"Enemy\" &amp;&amp; type == TYPE.PLAYER\n       || collision.gameObject.tag == \"Player\" &amp;&amp; type == TYPE.ENEMY)\n    {\n        isMove = true;\n    }\n}<\/code><\/pre>\n\n\n\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using System.Collections;using System.Collections.Generic;using UnityEngine; public class CharactorMove : Mono &hellip; <a href=\"http:\/\/www.tyosuke20xx.com\/blog\/?p=14340\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;C# \u304a\u306b\u3083\u3093\u3053\u5927\u6226\u4e89&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[33,29],"tags":[35,3],"class_list":["post-14340","post","type-post","status-publish","format-standard","hentry","category-c","category-unity","tag-c","tag-programming"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/14340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14340"}],"version-history":[{"count":1,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/14340\/revisions"}],"predecessor-version":[{"id":14341,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/14340\/revisions\/14341"}],"wp:attachment":[{"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14340"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tyosuke20xx.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}