ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2020ǯ10·î10Æü(ÅÚ) 22:08:56ÍúÎò
¿§¡¹¤ÊÊýË¡¤¬¤¢¤ë¤È»×¤¤¤Þ¤¹¤¬¡¢º£²ó¤Ï¡¢¥¨¥ê¥¢¤Î¾ðÊó¤ò¥Ç¡¼¥¿¥Ù¡¼¥¹²½¤·¡¢¤½¤Î¾ðÊó¤ò¸µ¤Ë°ÜÆ°¤Ç¤¤ëÈϰϤòÀ©¸Â¤¹¤ëÊýË¡¤Ç¼ÂÁõ¤ò¤·¤Æ¤¤¤¤Þ¤¹¡£
¡¡¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤ÏUnity¤Îµ¡Ç½¤Ç¤¢¤ë¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤òÍøÍѤ·¤Þ¤¹¡£
¤³¤³¤Ë¥¹¥Æ¡¼¥¸¤È¥¨¥ê¥¢¤Î¾ðÊó(²¿ÈÖÌܤΥ¨¥ê¥¢¡¢¤³¤Î¥¨¥ê¥¢¤Î°ÜÆ°ÈÏ°Ï¡¢¤³¤Î¥¨¥ê¥¢¤Ë½Ð¸½¤¹¤ëŨ¤Î¼ïÎà¡¢¤Ê¤É)¤ò¥Ç¡¼¥¿¤È¤·¤ÆÅÐÏ¿¤·¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹²½¤·¤Þ¤¹¡£
¡¡¤³¤Î¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤È¥¹¥Æ¡¼¥¸¤Î¾ðÊó¤ò´ÉÍý¤¹¤ëGameManager¥¯¥é¥¹¤òºî¤ê¡¢GameManager¤¬¸½ºß¤Î¥¨¥ê¥¢¤Î¾ðÊó¤ò´ÉÍý¤·¤Æ¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÈϢư¤ò¹Ô¤¤¤Þ¤¹¡£
¥¹¥Æ¡¼¥¸£²¡¢¥¨¥ê¥¢£³¤È¤¤¤¦¾ðÊó¤ò´ÉÍý¤·¡¢¤½¤Î¾ðÊó¤ò¸µ¤Ë¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò»²¾È¤·¤Æ¥²¡¼¥àÆâ¤ËÈ¿±Ç¤µ¤»¤Æ¤¤¤¤Þ¤¹¡£
¡¡¤³¤ì¤é¤ò¥í¥¸¥Ã¥¯²½¤·¡¢¼«Æ°¤ÇÆ°ºî¤¹¤ë¤è¤¦¤Ë¤·¤Æ¤¤¤¤Þ¤¹¡£
¡¡£±¡¥¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥ÈÍѤÎStageList¥¯¥é¥¹¤òºîÀ®¤¹¤ë ¡¡£²¡¥¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤¹¤ë ¡¡£³¡¥¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤Ë¥Ç¡¼¥¿¤òÅÐÏ¿¤·¤Æ¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤òºîÀ®¤¹¤ë ¡¡£´¡¥¥²¡¼¥à¤Î´ÉÍý¤ò¹Ô¤¦GameManager¥¯¥é¥¹¤òºîÀ®¤¹¤ë ¡¡£µ¡¥¥²¡¼¥à¤ò¼Â¹Ô¤·¤ÆÆ°ºî¤ò³Îǧ¤¹¤ë ¡¡£¶¡¥PlayerController¥¯¥é¥¹¤ò½¤Àµ¤·¡¢¥¨¥ê¥¢¤Ë¹ç¤ï¤»¤Æ°ÜÆ°¤Ç¤¤ëÈϰϤò¼«Æ°Åª¤ËÀ©¸Â¤¹¤ë
¡¡¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥ÈÍѤΥ¯¥é¥¹¤Ç¤¢¤ë¡¢StageList¥¯¥é¥¹¤òºîÀ®¤·¤Þ¤¹¡£
¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥ÈÍѤΥ¯¥é¥¹¤ÏMonoBehaviour¤ò·Ñ¾µ¤»¤º¤Ë¡¢ScriptableObject¥¯¥é¥¹¤ò·Ñ¾µ¤·¤Þ¤¹¡£
¡¡¤Þ¤¿¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¦Ì̤«¤é¡¢Ê£¿ô¤Î¥¯¥é¥¹¤òÆþ¤ì»Ò¥¯¥é¥¹¤È¤·¤Æ´ÉÍý¤·¤Þ¤¹¡£
¹½Â¤¤Î¥¤¥á¡¼¥¸¤Ï¼¡¤Î¤è¤¦¤Ê·Á¤Ç¤¹¡£
StageList ---- StageDatas(List) ¡¡ | ¡¡¡¡ | ----- StageData[0] ---- AreaDatas(List) | | ---- AreaData[0] | | ---- AreaData[1] | | ----- StageData[1] ---- AreaData(List) | |---- AreaData[0] | |---- AreaData[1]
StageList.cs
¡¡¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤ò·Ñ¾µ¤·¤Æ¤¤¤ë¥¯¥é¥¹¤ËÀë¸À¤·¤ÆÉÕÍ¿¤Ç¤¤ë°À¤Î£±¤Ä¤Ç¤¹¡£
¤³¤Îµ¡Ç½¤ò»È¤¦¤³¤È¤Ç¥¨¥Ç¥£¥¿¡¼¤Î³ÈÄ¥¤¹¤ëɬÍפʤ¯¡¢Unity¤Î¥á¥Ë¥å¡¼¤«¤é¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤Ç¤¤Þ¤¹¡£
¡¡°ú¿ô¤ÏǤ°Õ¤Ç¤¹¡£¡Ê¤Ê¤·¤Ç¤âÌäÂꤢ¤ê¤Þ¤»¤ó¡Ë¡¡¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë¤³¤È¤Ç¡¢¼«Í³¤Ë½ñ¤´¹¤¨¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡£
Âè1°ú¿ô¤Ç¤Ï¡¢¥¢¥»¥Ã¥ÈÀ¸À®»þ¤Ë»ØÄꤷ¤¿¥Õ¥¡¥¤¥ë̾¤ò¥Ç¥Õ¥©¥ë¥È̾¤È¤·¤Æɽ¼¨¤µ¤»¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
Âè2°ú¿ô¤Ç¤Ï¡¢¥¢¥»¥Ã¥ÈÀ¸À®»þ¤Î¥á¥Ë¥å¡¼¤Ëɽ¼¨¤¹¤ë¥á¥Ë¥å¡¼Ì¾¤òÅÐÏ¿¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
º£²ó¤Ï»ØÄꤷ¤Æ¤¤¤Þ¤»¤ó¤¬¡¢Âè3°ú¿ô¤Þ¤ÇÀßÄê¤Ç¤¤Þ¤¹¡£
¡¡[CreateAssetMenu(fileName = "StageList", menuName = "Create StageList")]
Unity¸ø¼°¥É¥¥å¥á¥ó¥Æ¡¼¥·¥ç¥ó
CreateAssetMenuAttribute
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡ºîÀ®¤·¤¿StageList¥¯¥é¥¹¤Î¾ðÊó¤ò»ý¤Ä¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤·¤Þ¤¹¡£
¡¡Unity¤Îº¸¾å¤Î¥á¥Ë¥å¡¼¤«¤é Assets => Create => Create StageList ¤ÈÁªÂò¤·¤Þ¤¹¡£(¤³¤Îµ¡Ç½¤ò»È¤¦¤¿¤á¤Ë¡¢Àè¤Û¤É¤Î[CreateAssetMenu()]°À¤ÎÀë¸À¤¬É¬ÍפǤ¹)
Æ°²è¡¡¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤ÎºîÀ®¼ê½ç
https://gyazo.com/3ff19b0fc2cf679362849022127f2e28
¡¡ProjectÆâ¤Ë StageList ¥¢¥»¥Ã¥È¤¬¿·¤·¤¯ºîÀ®¤µ¤ì¤Þ¤¹¡£¥¢¥¤¥³¥ó¤¬Â¾¤È°ã¤¦¤â¤Î¤Ç¤¹¡£¤³¤ì¤¬¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤Ê¤ê¤Þ¤¹¡£
̾Á°¤Ï¼«Í³¤ËÊѹ¹¤Ç¤¤Þ¤¹¤¬¡¢StageList ¤Ë¤·¤Æ¤ª¤¤¤¿Êý¤¬¤ï¤«¤ê¤ä¤¹¤¤¤Ç¤·¤ç¤¦¡£
¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È
¡¡
¡¡StageList¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤Ë Size 0 ¤Èɽ¼¨¤µ¤ì¤Æ¤¤¤ë¤È»×¤¤¤Þ¤¹¤Î¤Ç¡¢¤³¤Á¤é¤ò 1 ¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£
¤³¤Î Size ¤¬¡¢¥²¡¼¥à¤ËÅо줹¤ë¥¹¥Æ¡¼¥¸¿ô¤Ë¤Ê¤ê¤Þ¤¹¡£¸½ºß¤Ï¥¹¥Æ¡¼¥¸ 1 ¤òºîÀ®¤¹¤ëͽÄê¤Ê¤Î¤Ç¡¢¤³¤³¤ò 1 ¤ËÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£
StageList¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü
¡¡¤º¤¤¤Ö¤ó¤¿¤¯¤µ¤ó¤Î¹àÌܤ¬¤¢¤ë¤è¤¦¤Ë¸«¤¨¤Þ¤¹¤¬¡¢¡Ú£±¡Û¤Î¼ê½ç¤ÇºîÀ®¤·¤¿Æþ¤ì»Ò¥¯¥é¥¹¤Î¾ðÊ󤬽çÈÖ¤Ëɽ¼¨¤µ¤ì¤Æ¤¤¤ë¤È»×¤¤¤Þ¤¹¡£
¤³¤³¤Ë¥¨¥ê¥¢¤ÎÈֹ桢¥¨¥ê¥¢¤´¤È¤Î°ÜÆ°¤ÎÈÏ°Ï¡¢¥¨¥ê¥¢¤´¤È¤Ë½Ð¸½¤¹¤ëŨ¤ò¥Ç¡¼¥¿¤È¤·¤ÆÅÐÏ¿¤·¤Þ¤¹¡£
¡¡¤³¤ì¤ÏɬÍפʿô¤À¤±Áý¤ä¤»¤Þ¤¹¤Î¤Ç¡¢¥¨¥ê¥¢¿ô¤ò 4 ¤ËÀßÄꤹ¤ì¤Ð¡¢£´¤Äʬ¤Î¥Ç¡¼¥¿¤òÅÐÏ¿½ÐÍè¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡³Æ¹àÌܤ´¤È¤Ë¸«¤Æ¤¤¤¤Þ¤¹¡£
StageDatas/Size¡¡¥¹¥Æ¡¼¥¸¿ô¤ÎÀßÄê¤Ç¤¹¡£¤³¤Î»ÒElement¤¬¥¹¥Æ¡¼¥¸¤Ç¤¹¡£
¥¹¥Æ¡¼¥¸¤ò 3 ¤ÄÍÑ°Õ¤·¤¿¾ì¹ç¡¡Element 0 - 2
StageDatas/Element x/AreaDatas¡¡¥¨¥ê¥¢¿ô¤ÎÀßÄê¤Ç¤¹¡£¤³¤Î»ÒElement¤¬¥¨¥ê¥¢¤Ç¤¹¡£
¥¨¥ê¥¢¤ò 3 ¤ÄÍÑ°Õ¤·¤¿¾ì¹ç¡¡Element 0 -2
StageDatas/Element x/AreaDatas/Element x¡¡³Æ¥¨¥ê¥¢¤Î¾ÜºÙ¤òÅÐÏ¿¤·¤Þ¤¹¡£¥¨¥ê¥¢¤ÎÈֹ桢¥¨¥ê¥¢¤Î°ÜÆ°À©¸Â¡¢Å¨¤Î¼ïÎà
¡¡¤Þ¤º¤ÏÆ°ºî³Îǧ¤Î¤¿¤á¤Ë¡¢¥¹¥Æ¡¼¥¸ 1 ¤Îʬ¤òÅÐÏ¿¤·¤Þ¤¹¡£
¡¡¥Ò¥¨¥é¥ë¥¡¼¾å¤Ç±¦¥¯¥ê¥Ã¥¯¤·¤Æ¥á¥Ë¥å¡¼¤òɽ¼¨¤·¡¢CreateEmpty ¤òÁªÂò¤·¤Þ¤¹¡£Ì¾Á°¤òGameManager¤ËÊѹ¹¤·¤Þ¤¹¡£
¡¡GameManager¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ËÀè¤Û¤ÉºîÀ®¤·¤¿GameManager¥¯¥é¥¹¤ò¥É¥é¥Ã¥°¥¢¥ó¥É¥É¥í¥Ã¥×¤·¤Æ¥¢¥¿¥Ã¥Á¤·¤Þ¤¹¡£
GameManager¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÁªÂò¤·¤Æ¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤òɽ¼¨¤·¡¢¥¢¥µ¥¤¥ó¾ðÊó¤ò³Îǧ¤·¤Þ¤¹¡£
¡¡
GameManager¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü
¡¡StageListÊÑ¿ô¤Ë¤Ï¡¢StageList¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤ò¥É¥é¥Ã¥°¥¢¥ó¥É¥É¥í¥Ã¥×¤·¤Æ¥¢¥µ¥¤¥ó¤·¤Þ¤¹¡£
¤³¤ì¤ÇÅÐÏ¿¤·¤¿¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò¥²¡¼¥àÆâ¤Ë»²¾È½ÐÍè¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡PlayerControllerÊÑ¿ô¤Ë¤Ï¡¢PlayerController¤ò¥¢¥¿¥Ã¥Á¤·¤Æ¤¤¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¥Ò¥¨¥é¥ë¥¡¼¤«¤é¥É¥é¥Ã¥°¥¢¥ó¥É¥É¥í¥Ã¥×¤·¤Æ¥¢¥µ¥¤¥ó¤·¤Þ¤¹¡£
¡¡Â¾¤Î¹àÌܤϥ²¡¼¥à¤Î¼Â¹Ô¤ÈƱ»þ¤Ë¥¢¥µ¥¤¥ó¤µ¤ì¤ë¹àÌܤˤʤê¤Þ¤¹¡£¤Þ¤¿¥¨¥ê¥¢¤ò°ÜÆ°¤¹¤ëºÝ¤Ë¡¢Æ°Åª¤ËÊѹ¹¤µ¤ì¤ë¹àÌܤǤ⤢¤ê¤Þ¤¹¡£
¡¡¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤Ë¡¢°ÜÆ°ÈϰϤòÅÐÏ¿¤·¤Æ¤¯¤À¤µ¤¤¡£
¥²¡¼¥à¤Î¼Â¹Ô¤ÈƱ»þ¤Ë¡¢GameManager¤ÎLeftLimitPos¡ÁBackLimitPos¤Þ¤Ç¤Î£´¤Ä¤ÎÃͤˡ¢¼«Æ°Åª¤Ë¤³¤ÎÃͤ¬Æþ¤ì¤ÐÀ®¸ù¤Ç¤¹¡£
¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤ÎMoveLimit
¸¡¾ÚÆ°²è¢¡¡StagaList¤«¤é¥Ç¡¼¥¿¤¬È¿±Ç¤µ¤ì¤Æ¤¤¤ë¤«³Îǧ(LeftLimitPos¡ÁBackLimitPos¤Þ¤Ç¤Î£´¤Ä¤ÎÃͤ¬Æþ¤ë)
https://gyazo.com/74ed2ca8347f57ef9f6648dd162e5bd7
¡¡
¸¡¾ÚÆ°²è¢¡¡StagaList¤«¤é¥Ç¡¼¥¿¤¬È¿±Ç¤µ¤ì¤Æ¤¤¤ë¤«³Îǧ(MoveLimit¤ÎÃͤ¬Æþ¤ë)
https://gyazo.com/d56eeb034b10662015ad17794a9b9e75
¡¡Ìµ»ö¤ËÃͤ¬Æþ¤Ã¤¿¤é¡¢ºÇ¸å¤Ë¡¢PlayerController¥¯¥é¥¹¤ò½¤Àµ¤·¡¢°ÜÆ°¤ÎÀ©¸ÂÈϰϤˤ³¤Î¥¨¥ê¥¢¤ÎÃͤòÈ¿±Ç½ÐÍè¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
¡¡StageList¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤Ï¥¨¥ê¥¢¤Î¾ðÊó¤È¤·¤Æ¥¥ã¥é¤Î°ÜÆ°ÈϰϤξðÊ󤬤¢¤ê¤Þ¤¹¡£
¤³¤Î¾ðÊó¤ò»È¤¦¤è¤¦¤Ë¤¹¤ì¤Ð¡¢¥²¡¼¥à¤Î¿Ê¹Ô¤Ë¹ç¤ï¤»¤Æ¥¥ã¥é¤Î°ÜÆ°ÈϰϤò¼«Æ°Åª¤ËÀ©¸Â¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡£
¡¡¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤ÏÇÛÎó¤äList¤Ø¤Î»²¾È¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤¿¤á¡¢Element¤ÎÃͤò»²¹Í¤Ë¤·¤ÆÃͤÎÅÐÏ¿¤ò¹Ô¤¤¤Þ¤¹¡£
Î㤨¤Ð¡¢¥¹¥Æ¡¼¥¸£±¤Î¾ì¹ç¡¢Element¤ÎÈÖ¹æ¤È¤·¤Æ¤Ï 0 ¤ÎÉôʬ¤ò»²¾È¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£Ãí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡PlayerController¥¯¥é¥¹¤ò½¤Àµ¤·¡¢Àë¸À¥Õ¥£¡¼¥ë¥É¤«¤é¥Ç¥Ð¥Ã¥°¤ÇÍøÍѤ·¤Æ¤¤¤¿MoveLimitÊÑ¿ô¤òºï½ü¤·¤Æ¤¯¤À¤µ¤¤¡£
Âå¤ï¤ê¤Ë¡¢GameManager¤Î¥¢¥µ¥¤¥ó¤òÄɲ䷤Ƥ¯¤À¤µ¤¤¡£
¡¡¤Þ¤¿FixedUpdate¥á¥½¥Ã¥É¤ò½¤Àµ¤·¡¢¼ÂºÝ¤Ë¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î»ý¤Ä¥¨¥ê¥¢¤Î¾ðÊó¤òÈ¿±Ç¤·¤ÆÀ©¸æ¤¬¹Ô¤ï¤ì¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
PlayerController.cs
¡¡½¤Àµ¤¬½ªÎ»¤·¤¿¤é¡¢GameManager¤ò¥¢¥µ¥¤¥ó¤·¡¢¼ÂºÝ¤Ë¥¥ã¥é¤ò°ÜÆ°¤µ¤»¤Æ¤ß¤Þ¤·¤ç¤¦¡£À©¸ÂÈÏ°ÏÆ⤷¤«°ÜÆ°¤Ç¤¤Ê¤±¤ì¤ÐÌäÂꤢ¤ê¤Þ¤»¤ó¡£
¡¡
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯