ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2021ǯ02·î17Æü(¿å) 14:13:38ÍúÎò
¼ê½ç£¶¡¡¡Ý¥¹¥ï¥¤¥×½èÍý¤ò¼ÂÁõ¡Ý
£±£±¡¥¥¹¥ï¥¤¥×ÍÑ¥¹¥¯¥ê¥×¥È¤òºîÀ®¤¹¤ë £±£²¡¥¼êµåÍÑ¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤¹¤ë(¥¹¥ï¥¤¥×¤ÇÀ¸À®¤µ¤ì¤¿CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤È¤ÎÀÜ¿¨È½Äê¤òÄɲ乤ë)
¡¡¿·¤·¤¤³Ø½¬ÆâÍƤϡ¢°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£
¡¦Input.mousePosition ÊÑ¿ô ¡¦Camera.ScreenToWorldPoint(Vector3 position)¥á¥½¥Ã¥É ¡¦OR(||)±é»»»Ò¡¡ ¡¦Layer ¤ÎÀßÄê
¡¡²èÌ̤ò¥¹¥ï¥¤¥×(Unity¥¨¥Ç¥£¥¿¡¼¾å¤Ç¤Ï¥Þ¥¦¥¹¤Ç¥É¥é¥Ã¥°)¤·¤Æ¤¤¤ë´Ö¡¢¥¥å¡¼Ìò¤ÎCueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·¡¢
¼êµå¤ÈÀÜ¿¨¤·¤¿ºÝ¤Ë¡¢¼êµå¤òÃƤ¯¤è¤¦¤Ë¤·¤Æ¥²¡¼¥à¤ò¿Ê¹Ô¤µ¤»¤ëÌò³ä¤òÍ¿¤¨¤Þ¤¹¡£
https://gyazo.com/4b6e32e23f8c0ac3990601f3b79664db
¡¡²èÌ̤Υ¹¥ï¥¤¥×¤ËƱ´ü¤·¤Æ¡¢¥×¥ì¥Õ¥¡¥Ö¤Ë¤·¤Æ¤¢¤ë CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤¹¤ëµ¡Ç½¤ò¼ÂÁõ¤·¤Þ¤¹¡£
¡¡°Ê²¼¤Î¥µ¥¤¥ÈÍͤε»ö¤ò»²¹Í¤Ë¥¹¥¯¥ê¥×¥ÈºîÀ®¤·¤Æ¤¤¤Þ¤¹(¤¿¤À¤·¤³¤Á¤é¤Î¥µ¥¤¥ÈÍͤϣ³£Ä´Ä¶¤Ç¤Î¥¹¥¯¥ê¥×¥È¤Ç¤¢¤ë¤¿¤áÆâÍƤϣ²£ÄÍѤËÊѹ¹¤·¤Æ¤¤¤Þ¤¹¡£)
»²¹Í¥µ¥¤¥È
@NickyÍÍ
[Unity] Åö¤¿¤êȽÄê¤Î¤¢¤ëÀþ¤ò°ú¤¯¡¡¡ÁĶ´Ê°×ÈÇ¡Á
https://qiita.com/Nicky/items/348a2b3da591c9c5ff39
¡¡Scripts¥Õ¥©¥ë¥ÀÆâ(¤â¤·¤â¥Õ¥©¥ë¥À¤¬¤Ê¤±¤ì¤ÐºîÀ®¤·¤Æ¤¯¤À¤µ¤¤)¤Ç±¦¥¯¥ê¥Ã¥¯¤·¤Æ¥á¥Ë¥å¡¼¤òɽ¼¨¤·¡¢Create => C# Script ¤òÁªÂò¤·¡¢Ì¾Á°¤ò CueLiner ¤ËÊѹ¹¤·¤Þ¤¹¡£
CueLiner.cs
¡¡Input¥¯¥é¥¹¤Î»ý¤ÄstaticÊÑ¿ô¤Ç¤¹¡£¸½ºß¤Î¥Þ¥¦¥¹¤Î°ÌÃ֤Υԥ¯¥»¥ëºÂɸ(x, y)¤ò¼èÆÀ¤·¤Þ¤¹¡£¥Þ¥¦¥¹¤Î¾ðÊó¤ÏÊ¿Ì̤Ǥ¢¤ë¤¿¤á¡¢z ºÂɸ¤Î¾ðÊó¤Ï¤¢¤ê¤Þ¤»¤ó¡£
¤³¤Î¾ðÊó¤È¼¡¤ÎScreenToWorldPoint¥á¥½¥Ã¥É¤òÁȤ߹ç¤ï¤»¤ë¤³¤È¤Ë¤è¤ê¡¢¥Þ¥¦¥¹¤Î°ÌÃÖ¤ò¥²¡¼¥àÆâ¤ÎºÂɸ¤ËÊÑ´¹¤·¤Æ¤¤¤Þ¤¹¡£
¡¡º£²ó¤Î¥¹¥¯¥ê¥×¥È¤Ç¤Ï¾Êά¤·¤Æ¤¤¤Þ¤¹¤¬¡¢¤É¤¦¤¤¤Ã¤¿Ãͤ¬¼èÆÀ¤Ç¤¤Æ¤¤¤ë¤«¤ÏDebug.Log¤ò»ÈÍѤ¹¤ë¤³¤È¤¬³Îǧ¤Ç¤¤Þ¤¹¤Î¤Ç¡¢¼ÂºÝ¤ËµºÜ¤·¤ÆÃͤò³Îǧ¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
Input.mousePosition
https://docs.unity3d.com/ja/2019.4/ScriptReference...
¡¡Camera¥¯¥é¥¹¤Î»ý¤Ä¥á¥½¥Ã¥É¤Î£±¤Ä¤Ç¤¹¡£¥«¥á¥é¤ò»È¤¤¡¢°ú¿ô¤ÎºÂɸ¤ò¥ï¡¼¥ë¥ÉºÂɸ¤ËÊÑ´¹¤·¤Þ¤¹¡£
// ¥Þ¥¦¥¹¤Ç¥¯¥ê¥Ã¥¯¤·¤¿°ÌÃÖ¤ò¼èÆÀ touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
¡¡º£²ó¤Ï°ú¿ô¤Ë¥Þ¥¦¥¹¤ÎºÂɸ¤ò»ØÄꤷ¡¢¤½¤Î°ÌÃÖ¤ò¥²¡¼¥à¤Î¥ï¡¼¥ë¥ÉºÂɸ¤ËÊÑ´¹(Ìá¤êÃÍ)¤¹¤ë½èÍý¤ò¹Ô¤¦¤³¤È¤Ç¥Þ¥¦¥¹¤Î°ÌÃ֤ȥ²¡¼¥à²èÌ̤ȤξðÊó¤òƱ´ü¤µ¤»¤Æ¤¤¤Þ¤¹¡£
¡¡Ìá¤êÃͤȤ·¤Æ¤Ï Vector3 ·¿¤ÇÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢º£²ó¤Ï£²£Ä¥²¡¼¥à¤Ç¤¹¤Î¤Ç¡¢Vector2·¿¤Ç¼õ¤±¼è¤Ã¤Æ¤¤¤Þ¤¹¡£(touchPos ÊÑ¿ô¤Ï Vector2·¿¤Ç¤¹)
¤³¤Î¾ì¹ç¡¢Vector3·¿¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¤¬ÌäÂê¤Ê¤¯ÂåÆþ½èÍý¤¬¹Ô¤ï¤ì¤Þ¤¹(Âè3°ú¿ô¤ÎÃÍ(z)¤¬ÂåÆþ¤µ¤ì¤Ê¤¤½èÍý¤Ë¤Ê¤ê¤Þ¤¹¡£)
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
Camera.ScreenToWorldPoint
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡CueLiner¥¹¥¯¥ê¥×¥È¤ò¥¢¥¿¥Ã¥Á¤¹¤ë¤¿¤á¡¢¶õ¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò£±¤Ä¡¢CanvasÆâ¤ËºîÀ®¤·¤Þ¤¹¡£¡Êɬ¤ºCanvasÆâ¤ËºîÀ®¤·¤Æ¤¯¤À¤µ¤¤¡Ë
CueLiner¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥Ò¥¨¥é¥ë¥¡¼²èÁü
¡¡Ì¾Á°¤ò CueLiner ¤ËÊѹ¹¤·¡¢ºîÀ®¤·¤¿CueLiner¥¹¥¯¥ê¥×¥È¤ò¥É¥é¥Ã¥°¥¢¥ó¥É¥É¥í¥Ã¥×¤·¤Æ¥¢¥¿¥Ã¥Á¤·¤Þ¤¹¡£
¡¡CueLiner¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÁªÂò¤·¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤ò³Îǧ¤·¤Þ¤¹¡£
CueLiner¥¹¥¯¥ê¥×¥È¤Î¥¢¥µ¥¤¥ó¾ðÊó¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤½¤ì¤¾¤ìÀßÄê¤ò¹Ô¤¤¤Þ¤¹¡£
¡¡cuelinePrefab ÊÑ¿ô¤Ë¤Ï¡¢ProjectÆâ¤ÎPrefabs ¥Õ¥©¥ë¥À¤Ë¤¢¤ë CueLine ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¥É¥é¥Ã¥°¥¢¥ó¥É¥É¥í¥Ã¥×¤·¤Æ¥¢¥µ¥¤¥ó¤·¤Þ¤¹¡£
¡¡minCuelineLength ÊÑ¿ô¤Ï¡¢¤É¤Î°Ì¥¹¥ï¥¤¥×¤ò¹Ô¤¨¤Ð CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·»Ï¤á¤ë¤«¡¢¤½¤ÎºÇ¾®ÃͤòÀßÄꤷ¤Þ¤¹¡£
0 ¤Ç¤¢¤ì¤Ð¤Û¤È¤ó¤É¥¹¥ï¥¤¥×¤»¤º¤ËÀ¸À®¤·¤Æ¤·¤Þ¤¤¤Þ¤¹¤Î¤Ç¡¢0.3f - 0.5f °Ì¤ÎÃͤòÀßÄꤷ¡¢Ä´À°¤ò¹Ô¤¤¤Þ¤¹¡£¤³¤³¤Ç¤Ï 0.3f ¤ÇÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£
¡¡duration ÊÑ¿ô¤Ë¤Ï¡¢À¸À®¤µ¤ì¤¿ CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬¤É¤Î°Ì¥²¡¼¥à²èÌÌÆâ¤Ëɽ¼¨¤µ¤ì¤Æ¤¤¤ë¤«¤òÀßÄꤷ¤Þ¤¹¡£
¤¢¤Þ¤êŤ¤¤È¤¤¤Ä¤Þ¤Ç¤âCueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬»Ä¤ê³¤±¤Æ¤·¤Þ¤¦¤¿¤á¡¢¥¿¥¤¥ß¥ó¥°¤è¤¯ÃƤ¯¡¢¤È¤¤¤¦µóÆ°¤«¤é¤Ï±ó¤¯¤Ê¤ê¤Þ¤¹¡£
½é´üÃͤȤ·¤Æ¤Ï 0.2f - 0.5f ÄøÅÙ¤òÀßÄꤷ¡¢Ä´À°¤ò¹Ô¤Ã¤Æ¤¯¤À¤µ¤¤¡£¤³¤³¤Ç¤Ï 0.25f ¤ÇÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£
¡¡
CueLiner¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü
https://gyazo.com/2ede8e85535db119efc12dcac5d14b4a
¡¡¥²¡¼¥à¤ò¼Â¹Ô¤·¡¢¥²¡¼¥à²èÌ̤ò¥¹¥ï¥¤¥×¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£¥¹¥ï¥¤¥×¤Ë±è¤Ã¤Æ CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬Ê£¿ôÀ¸À®¤µ¤ì¤Æ¥é¥¤¥ó¾õ¤Ë¤Ê¤Ã¤Æ¤¤¤ì¤ÐÌäÂꤢ¤ê¤Þ¤»¤ó¡£
¡¡¼êµå¤ÈCueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤È¤òÀÜ¿¨¤µ¤»¤Æ¤ß¤Þ¤·¤ç¤¦¡£¤Þ¤ÀÃƤ¯½èÍý¤¬¤Ê¤¤¤¿¤á¡¢¤¤¤Þ¤Ï¥ª¥Ö¥¸¥§¥¯¥ÈƱ»Î¤¬ÊªÍýŪ¤Ë¤Ö¤Ä¤«¤Ã¤¿È¿Æ°¤Ç¾¯¤·¤·¤«Æ°¤¤Þ¤»¤ó¡£
¼¡¤Î¼ê½ç¤Ç¼êµå¤òÃƤ±¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
¡¡CueLine ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î Layer ¤òÁªÂò¤·¤Æ¥×¥ë¥À¥¦¥ó¥á¥Ë¥å¡¼¤òɽ¼¨¤·¡¢°ìÈÖ²¼¤Ë¤¢¤ë Add Layer¡Ä ¤òÁªÂò¤·¤Þ¤¹¡£
¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤ÎÆâÍƤ¬ Tags & Layers ¤È¤¤¤¦¹àÌܤËÀÚ¤êÂؤï¤ê¡¢Tag ¤È Layer ¤òÅÐÏ¿¤Ç¤¤ëÀßÄêÆâÍƤËÀÚ¤êÂؤï¤ê¤Þ¤¹¡£
¡¡Layers ¤òÁªÂò¤¹¤ë¤È User Layer ¤ÎÉôʬ¤Ë¿·¤·¤¯ Layer ¤òºîÀ®¤·¤ÆÅÐÏ¿¤Ç¤¤Þ¤¹¤Î¤Ç¡¢
User Layer 8 ¤Ë CueLine¡¡¤ÈÅÐÏ¿¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡¤â¤¦°ìÅÙ CueLine ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¥Ò¥¨¥é¥ë¥¡¼¤ÇÁªÂò¤·¤Æ¡¢Æ±¤¸¤è¤¦¤Ë Layer ¤òÁªÂò¤¹¤ë¤È¡¢¥×¥ë¥À¥¦¥ó¥á¥Ë¥å¡¼Æâ¤Ë¿·¤·¤¯Äɲä·¤¿
CueLine ¤¬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤½¤Á¤é¤òÅÐÏ¿¤·¤Æ¤¯¤À¤µ¤¤¡£
£±£²¡¥¼êµåÍÑ¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤¹¤ë(¥¹¥ï¥¤¥×¤ÇÀ¸À®¤µ¤ì¤¿CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤È¤ÎÀÜ¿¨È½Äê¤òÄɲ乤ë)
¡¡CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ËÀÜ¿¨¤·¤¿ºÝ¤Ë¡¢¼êµå¤¬ÃƤ«¤ì¤ÆÆ°¤¯¤è¤¦¤ËCharaBall¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤Þ¤¹¡£
¡¡OnCollisionEnter2D¥á¥½¥Ã¥É¤Ë¡¢CueLine Tag¤Îʬ´ô¤òÄɲä·¡¢CueLine ¤ÎTagÀßÄê¤Î¤¢¤ë CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ËÀÜ¿¨¤·¤¿ºÝ¤Î½èÍý¤òÄɲä·¤Þ¤¹¡£
¤Þ¤¿¤¹¤Ç¤Ë¤¢¤ë Wall Tag¤Îʬ´ôÉôʬ¤Ë¡¢¼¡¤Î¼ê½ç¤ÇÀÜ¿¨È½Äê¤ò¹Ô¤¦EnemyBall Tag ¤Îʬ´ô¤âÄɲ䷤Ƥª¤¤Þ¤¹¡£
CharaBall.cs
¡¡OR±é»»»Ò¤Ï¡¢¾ò·ï¼°¤ÇÍѤ¤¤é¤ì¤ë±é»»»Ò¤Ç¤¹¡£È¾³Ñ || ¤Ç¾ò·ï¼°¤ò¹½ÃÛ¤·¤Þ¤¹¡£
¤³¤ì¤Ïº¸¥ª¥Ú¥é¥ó¥É(¾ò·ï)¤¬ true ¤Î¾ì¹ç¤Ë¤Ïɾ²Á¤ò¤»¤º¡¢ false ¤Î¾ì¹ç¤Ë¤Î¤ß¾ò·ï¤ÎȽÄê¤ò¹Ô¤¤¤Þ¤¹¡£
¡¡¤Ä¤Þ¤ê¡¢¤É¤Á¤é¤«°ìÊý¤Î¾ò·ï¤òËþ¤¿¤»¤Ð¡¢ifʸ¤Î¾ò·ï¼°¤òËþ¤¿¤·¤¿¤³¤È¤Ë¤Ê¤ë±é»»»Ò¤Ç¤¹¡£
¡¡if (col.gameObject.tag == "Wall" || col.gameObject.tag == "EnemyBall") {
¡¡¤³¤ÎÎã¤Ç¤Ï¡¢»Ï¤á¤Ë Wall Tag ¤ò»ý¤Ä¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë¤«¤É¤¦¤«¤òȽÄꤷ¡¢true ¤Î¾ì¹ç¤Ë¤Ï¡¢ || °Ê¹ß¤Î¾ò·ï¤Ï¹Ô¤ï¤º¤Ë¾ò·ï¤òËþ¤¿¤·¤¿¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
µÕ¤Ë¡¢Wall Tag ¤¬ false ¤Î¾ì¹ç¤Ë¤Ï¡¢EnemyBall Tag ¤ÎȽÄê¤ò¹Ô¤¤¡¢true ¤Î¾ì¹ç¤Ë¤Ï¾ò·ï¤òËþ¤¿¤·¤¿¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡º£²ó¤Ï¤¢¤ê¤Þ¤»¤ó¤¬¡¢3¤Ä°Ê¾å¤Î¾ì¹ç¤Ç¤âƱÍͤˤʤê¤Þ¤¹¡£
¡¡¤³¤ì¤Ç½àÈ÷¤¬À°¤¤¤Þ¤·¤¿¡£¥²¡¼¥à¤ò¼Â¹Ô¤·¤Æ¡¢²èÌ̤ò¥¹¥ï¥¤¥×¤·¡¢CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¼êµå¤ËÀÜ¿¨¤µ¤»¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
¼êµå¤¬ÃƤ«¤ì¤ì¤ÐÀ®¸ù¤Ç¤¹¡£
¡¡¼êµå¤Î®ÅÙ¤¬ÃÙ¤¤¾ì¹ç¤Ë¤Ï¡¢CharaBall¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÁªÂò¤·¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤ÎCharaBall¥¹¥¯¥ê¥×¥È¤Î Speed ÊÑ¿ô¤ÎÃͤòÊѹ¹¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
¸¡¾Ú²èÁü¡¡²èÌ̤ò¥¹¥ï¥¤¥×¤·¤Æ CueLine¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·¡¢¼êµå¤òÃƤ¤¤Æ¤ß¤ë
https://gyazo.com/0fc783b2bce7636f67b148665bab32ae
¡¡¤â¤·¤â¾å¼ê¤¯¤¤¤«¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢¼ê½ç£´¡Á£¶¤Þ¤Ç¤ò¤â¤¦°ìÅÙÆɤßÊÖ¤·¤Æ¡¢ÀßÄ꤬ȴ¤±¤Æ¤¤¤Ê¤¤¤«¡¢¥¹¥¯¥ê¥×¥È¤Ë½ñ¤Ëº¤ì¤Ï¤Ê¤¤¤«¡¢³Îǧ¤ò¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
Tag¤ÎÀßÄê¤Î¾¡¢ParticleSystem¤ÎÀßÄê¤Ê¤É¡¢Â¿¤¯¤ÎÉôʬ¤¬½Å¤Ê¤Ã¤Æ½èÍý¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢£±¤Ä£±¤Ä½çÈ֤ˡ¢ÌäÂêÅÀ¤¬¤Ê¤¤¤«¤òÀÚ¤êʬ¤±¤Æ¤ß¤Æ¤¤¤¯¤³¤È¤¬ÂçÀڤǤ¹¡£
¡¡°Ê¾å¤Ç¤³¤Î¼ê½ç¤Ï½ªÎ»¤Ç¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯