ãUnity1ãã¦ããã£ã¡ãããå転ï¼OnCollisionEnter2D, Tag(ã¿ã°)ãã¦ããã£ã¡ãã縦ã¹ã¯ãã¼ã«2ã
Unity5.1.1f1 Personal(2015å¹´6æ)Â
Â
ãã®ã³ã³ãã³ãã¯ããã¦ããã£ã¡ããã©ã¤ã»ã³ã¹ãã§æä¾ããã¦ãã¾ã
Â
ååã®ç¶ãã§ãã
Â
èªåçã«æ¨ªç§»åããããã«ãªã£ãã®ã§ã次ã¯å£ã«ã¶ã¤ãã£ãæã«ãã£ã©ã¯ã¿ã¼ã
å転ãã¦ãå対æ¹åã¸æ»ãåããä½ãããã¨æãã¾ãã
ãç®æ¨ã å£ã«ã¶ã¤ãã£ãæããã£ã©ã¯ã¿ã¼ãå転ãããï¼
 ãã®ããã«ã¯ã»ã»ã»
â å£è¡çªæã®å½ããå¤å®
2Dã®å ´åå½ããå¤å®ã¯ããOnTriggerEnter2DãããOnCollisionEnter2DãããPhysics2D.Linecastãã®ï¼ã¤ã代表çãªãã®ã®ããã§ããä»åã¯ãã®ä¸ãããOnCollisionEnter2Dããå®è£ ãã¾ãï¼
 Â
OnCollisionEnterã¯ãBoxColliderçã®ã³ã©ã¤ãã¼ãè¨å®ããã¦ãããªãã¸ã§ã¯ãã«ã¶ã¤ãã£ãæå¦çãå®è¡ãã¾ããããã®2Dçã¨ãããã¨ã§ããã
Â
ã¾ãã¯å£ãä½ãã¾ããããHierarchyãã¥ã¼ããCreate>3D Object>Cubeãé¸æãã以ä¸ã®ããã«è¨å®ãã¾ãã
Â
Cube(å£)ã®è¨å®
Â
ãããªæã
Â
ãã®ã¾ã¾ã ã¨å°é¢ã«ã¦ããã£ã¡ãããçå°ããæã«ãå¦çãå®è¡ããã¦ãã¾ãã¾ãã®ã§ãCube(å£)ã«ãWallãã¨ããã¿ã°ãä»ããWallã«ã¶ã¤ãã£ãæã«ã ãå¦çãå®è¡ããããã«ãã¾ãã
Â
Inspectorãã¥ã¼ã®TagããAdd Tagãé¸æ
Â
Wallã¿ã°ãä½æãã
Â
Cube(å£)ã®Inspectorãã¥ã¼ã«æ»ãTagãè¨å®Â
Â
Â
â¡ãã£ã©ã¯ã¿ã¼å転å¦ç
gameObject.transform.localScale.xã«-1ããããã¨ãç»åãå転ããããã¨ãã§ãã¾ãã
â¢é²è¡æ¹åãé転ãããÂ
â¡ãã£ã©ã¯ã¿ã¼å転ã®çµæãgameObject.transform.localScale.xã-1ã«ãªã£ãã1ã«ãªã£ããããã®ã§ãååä½æããç¹å®ã®æ¹åã¸åãå ããvelocityã®Xã«gameObject.transform.localScale.xããããã¨ã§ãå対æ¹åã¸ã®é²è¡ãå®ç¾ããããã¨ãã§ãã¾ãã
Â
 ã¨ããããã§ããã¡ããã½ã¼ã¹ã§ãã
Â
Â
ãçµæã
å£ã«åãã£ã¦é²ã¿
Â
ã¶ã¤ããã¨å対æ¹åã¸
Â
ãã¾ãããã¾ããï¼
Â
ä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
Â