ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2020ǯ12·î16Æü(¿å) 16:00:32ÍúÎò
¡¡Input.GetAxis¥á¥½¥Ã¥É¤Ï¡¢Unity¤Î»ý¤Ä Input ¥¯¥é¥¹¤¬°·¤¦¥á¥½¥Ã¥É¤Î£±¤Ä¤Ç¤¹¡£
ÆþÎϤÎȽÄê¤ò¹Ô¤¦¥á¥½¥Ã¥É¤Ç¤¢¤ë¤¿¤á¡¢Â¾¤ÎInput·Ï¤Î¥á¥½¥Ã¥É¤ÈƱ¤¸¤è¤¦¤Ë Update ¥á¥½¥Ã¥ÉÆâ¤Ëµ½Ò¤ò¤·¤ÆÍøÍѤ·¤Þ¤¹¡£
Input.GetKey¥á¥½¥Ã¥É¤äInput.GetButton¥á¥½¥Ã¥É¤È¤Ï°Û¤Ê¤ê¡¢bool ·¿¤Ç¤Ï¤Ê¤¯¤Æ¡¢float ·¿¤ÎÌá¤êÃͤòÊÖ¤¹¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¡¡
void Update(){ float vertical = Input.GetAxis("Vertical"); float horizontal = Input.GetAxis("Horizontal"); }
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
Input.GetAxis
https://docs.unity3d.com/ja/current/ScriptReferenc...
Qiita RyotaMurohoshi ÍÍ
Input.GetAxis¤ÈInputManager¤Î´ØÏ¢ÀßÄê¤Ë¤Ä¤¤¤Æ
https://qiita.com/RyotaMurohoshi/items/7868752a3f0...
¡¡Input.GetAxis¥á¥½¥Ã¥É¤Ï¡¢°ú¿ô¤È¤·¤Æ string ·¿¤òÀßÄꤷ¤Æ¤¤¤Þ¤¹¤¬¡¢¤³¤Îʸ»úÎó¤Ë¤Ï InputManager ¤ÇÀßÄꤷ¤Æ¤¤¤ëʸ»úÎó¤ò»ØÄꤹ¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
Input.GetButton·Ï¤Î¥á¥½¥Ã¥É¤ÈƱ¤¸¤Ç¤¹¡£
¡¡Unity¤Îº¸¾å¤Ë¤¢¤ë¥á¥Ë¥å¡¼¤ò¡¡Edit => Project Settings¡¡¤ÈÁªÂò¤·¤Æ¤¤¤¯¤È¡¢Project Settings¤È¤¤¤¦¥¦¥¤¥ó¥É¥¦¤¬³«¤¤Þ¤¹¡£
¤³¤ÎProject Settings ¥¦¥¤¥ó¥É¥¦¤Îº¸Â¦¤¬¥á¥Ë¥å¡¼¤Ë¤Ê¤Ã¤Æ¤ª¤ê¡¢InputManager¤È¤¤¤¦¹àÌܤ¬¤¢¤ê¤Þ¤¹¤Î¤Ç¤½¤Á¤é¤òÁªÂò¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
²èÁü¤Î¤è¤¦¤Êɽ¼¨¤Ë¤Ê¤ë¤È»×¤¤¤Þ¤¹¡£
¡ã¼ê½çÆ°²è¡¡InputManager¤Îɽ¼¨ÊýË¡¡ä
https://gyazo.com/56c0b7d6a4bc1d43e145f249e25a3e0e
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥Þ¥Ë¥å¥¢¥ë
Input Manager
https://docs.unity3d.com/ja/2019.4/Manual/class-In...
¡¡»î¤·¤Ë¡¢Vertical ¤È¤¤¤¦¹àÌܤòÁªÂò¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£¾ÜºÙ¾ðÊó¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
InputManager¤ÎVertical
¤³¤ÎÃæ¤Î Vertical ¤È¤¤¤¦¹àÌܤÎÃæ¤Ë¡¢Name ¤È¤¤¤¦Éôʬ¤¬¤¢¤ê¤Þ¤¹¡£
¤³¤Î Name ¤¬Ê¸»úÎó¤Ê¤Î¤Ç¤¹¤¬¡¢¤³¤Îʸ»úÎó¤òÀè¤Û¤É¤Î Input.GetAxis¥á¥½¥Ã¥É¤Î°ú¿ô¤È¤·¤Æµ½Ò¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
Veritcal¤Ï¡¢¿âľ¡¢¤È¤¤¤¦°ÕÌ£¤Îñ¸ì¤Ç¤¹¡£
float vertical = Input.GetAxis("Vertical"); <= ¤³¤Î Vertical ¤Îʸ»úÎ󤬡¢InputManager¤Î Name ¤È¤Ä¤Ê¤¬¤Ã¤Æ¤¤¤ë¡£¤½¤Î¤¿¤á¡¢Ê¸»úÎ󤬹çÃפ·¤Æ¤¤¤ëɬÍפ¬¤¢¤ë
¡¡Input.GetAxis¥á¥½¥Ã¥É¤Îʸ»úÎó¤Î»ØÄê¤Ï¡¢Âçʸ»ú¡¦¾®Ê¸»ú¤¬¶èÊ̤µ¤ì¤Þ¤¹¤Î¤Ç¡¢¾®Ê¸»ú¤Ç vertical ¤È½ñ¤¯¤È¼Â¹Ô»þ¤Ë¥¨¥é¡¼¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
InputManager¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë Name ¤Î¤Ä¤Å¤ê¤Çµ½Ò¤·¤Þ¤·¤ç¤¦¡£
¡¡¤Ç¤Ï¤³¤Î Vertical ¤È¤¤¤¦Ê¸»úÎó¤ò»ØÄꤷ¤¿¾ì¹ç¤Ë¡¢°ìÂΤɤΥ¡¼ÆþÎϤòȽÄꤷ¤Æ¤¯¤ì¤ë¤Î¤«¡¢¤È¤¤¤¦Éôʬ¤Ç¤¹¤¬
Àè¤Û¤É¤Î InputManager ¤ÎÃæ¤Ë¤¢¤ë¡¢Vertical ¤Î¹àÌÜÆâ¤Ë¡¢¥¡¼¤ò»ØÄꤷ¤Æ¤¤¤ë¾ì½ê¤¬¤¢¤ê¤Þ¤¹¡£
²èÁü¤ò¸«¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
¡¡Negative Button ¤È Positive Button ¤Ë¡¢down¤È up ¤¬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤Ï¥¡¼¥Ü¡¼¥É¤Î²¼Ìð°õ¤È¾åÌð°õ¤Î¤³¤È¤Ç¤¹¡£
¤Þ¤¿¡¢ Alt Negative Button ¤È Alt Positive Button ¤Ë¤â s ¤È w ¤¬ÅÐÏ¿¤µ¤ì¤Æ¤Þ¤¹¡£¤³¤ì¤â¥¡¼¥Ü¡¼¥É¤Î S¥¡¼¤È W¥¡¼¤Ç¤¹¡£
¡¡¤Ä¤Þ¤ê¡¢Input.GetAxis("Vertical") ¤È¤¤¤¦Ì¿Îá¤ò¼Â¹Ô¤¹¤ë¤È¡¢¾åµ¤Î£´¤Ä¤Î¥¡¼ÆþÎϤòȽÄꤷ¤Æ¤½¤Î¥¡¼¤ÎÆþÎϤ¬¤¢¤Ã¤¿¤«¤É¤¦¤«¤ò½èÍý¤·¤Æ¤¯¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
¾¯¤·½èÍý¤ÎÆâÍƤϰ㤤¤Þ¤¹¤¬¡¢°Ê²¼¤Î½èÍý¤ò¡¢£±Ê¸¤Ç¼ÂÁõ¤·¤Æ¤¤¤ë¥¤¥á¡¼¥¸¤Ç¤¹¡£
float vertical; if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { vertical = 1.0f; } if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { vertical = -1.0f; }
¡¡¤Þ¤¿¤â¤¦£±¤Ä¤Î¥á¥ê¥Ã¥È¤È¤·¤Æ¤Ï¡¢¥¡¼¤ÎÆþÎÏÃͤò InputManager ¤«¤éÊѹ¹¤Ç¤¤ë¤¿¤á¡¢¥¹¥¯¥ê¥×¥È¤òÊѹ¹¤»¤º¤Ë¥¡¼¤ÎÊѹ¹¤¬¹Ô¤¨¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¤³¤ì¤Ï Input.GetButton·Ï¤ÈƱ¤¸¥á¥ê¥Ã¥È¤Ç¤¹¡£
float vertical = Input.GetAxis("Vertical");
¡¡Input.GetAxis¥á¥½¥Ã¥É¤Î½èÍý¤Ï±¦ÊդνèÍý¤Ê¤Î¤Ç¡¢½èÍý¤Î·ë²Ì¤¬Ìá¤êÃͤȤ·¤Æº¸ÊÕ¤ËÂåÆþ¤µ¤ì¤Þ¤¹¡£
½é´üÀßÄê¤Ç¤³¤ì¤Ï¡¢¥¡¼¥Ü¡¼¥É¤Î¾å¡¢²¼¡¢¤¢¤ë¤¤¤Ï S¡¢W¡¡¤Î¤¤¤º¤ì¤«¤Î¥¡¼ÆþÎϤò¤·¤¿¤é¡¢¤½¤Î½èÍý·ë²Ì¤òº¸ÊդΠvertical ÊÑ¿ô¤ËÂåÆþ¤¹¤ë¤È¤¤¤¦½èÍý¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¥¡¼¥Ü¡¼¥É¤Î¾åÌð°õ¡¢¤¢¤ë¤¤¤Ï W ¤òÆþÎϤ¹¤ë¤È 0.1f ¡Á 1.0f ¤ÎÃͤ¬ÂåÆþ¤µ¤ì¤Þ¤¹¡£
º¹¤¬¤¢¤ë¤Î¤Ï¡¢²¡¤·¤Æ¤¤¤ë»þ´Ö¤¬Ä¹¤¤¤Û¤É 1.0f ¤Ë¶á¤Å¤¯¤è¤¦¤ËÀ©¸æ¤µ¤ì¤Æ¤¤¤ë¤¿¤á¤Ç¤¹(¥¢¥Ê¥í¥°¥¹¥Æ¥£¥Ã¥¯¤Î¥¤¥á¡¼¥¸)¡£
¡¡¥¡¼¥Ü¡¼¥É¤Î²¼Ìð°õ¡¢¤¢¤ë¤¤¤Ï S ¤òÆþÎϤ¹¤ë¤È¡¢- 0.1f ¡Á - 1.0f ¤ÎÃͤ¬ÂåÆþ¤µ¤ì¤Þ¤¹¡£
¡¡¤³¤Î¿ôÃͤÎÆ°¤¤ò³Îǧ¤¹¤ë¤Ë¤Ï¡¢Debug.Log¤òÍøÍѤ·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
¼ÂºÝ¤Ë¤É¤Î¤è¤¦¤Ê½èÍý¤¬Æ°¤¤¤Æ¤¤¤ë¤«¤òConsole¥Ó¥å¡¼¤Ë¤Æ³Îǧ¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
float vertical = Input.GetAxis("Vertical"); ¡¡Debug.Log(vertical); // <= ÄɲÃ
¡ã¸¡¾ÚÆ°²è¡¡Debug.Log¤ò»È¤Ã¤Æ½èÍý¤Îή¤ì¤òÄɤ¦¡ä
https://gyazo.com/253729f72781901bb27dcfa353f4bb70
¡¡Æ±¤¸¼ïÎà¤Î¥á¥½¥Ã¥É¤Ë¡¢Input.GetAxisRaw¥á¥½¥Ã¥É¤¬¤¢¤ê¤Þ¤¹¡£¤³¤Á¤é¤ÏÌá¤êÃͤȤ·¤Æ¡¢Ãæ´ÖÃͤò¼è¤é¤º¤Ë¡¢1.0f¡¢¤¢¤ë¤¤¤Ï -1.0f ¤Î¤ß¤ò¼èÆÀ¤·¤Æ¤¯¤ì¤Þ¤¹¡£
½ñ¼°¤ä»ÈÍÑÊýË¡¤Ï¡¢Input.GetAxis¥á¥½¥Ã¥É¤ÈƱ¤¸¤Ç¤¹¡£
void Update(){ float vertical = Input.GetAxisRaw("Vertical");¡¡¡¡¡¡¡¡¡¡// ÆþÎϤò¼õ¤±ÉÕ¤±¤ë¤È 1.0f ¤« -1.0f¤Î¤ß¤òÌ᤹ Debug.Log(vertical); float horizontal = Input.GetAxisRaw("Horizontal"); // ÆþÎϤò¼õ¤±ÉÕ¤±¤ë¤È 1.0f ¤« -1.0f¤Î¤ß¤òÌ᤹ }
¡ã¸¡¾ÚÆ°²è¡¡Debug.Log¤ò»È¤Ã¤Æ½èÍý¤Îή¤ì¤òÄɤ¦¡ä
https://gyazo.com/31ce3b2e2630b33ef19cb0c941c5865a
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯