Unity¤Ë´ØÏ¢¤¹¤ëµ­»ö¤Ç¤¹

¡¡¾ã³²Êª¤Î¹¶·â¤Î½èÍý¤Ë¤Ä¤¤¤Æ¡¢½èÍý¤ò¹Í¤¨¤ÆÄɲä·¤Þ¤¹¡£



¡¡°Ê²¼¤ÎÆâÍƤǽçÈ֤˼ÂÁõ¤ò¿Ê¤á¤Æ¤¤¤­¤Þ¤¹¡£

¼ê½ç£±£³¡¡¡¼¾ã³²Êª¤Î¹¶·â½èÍý¡¼
£²£°¡¥¾ã³²Êª¤Î¹¶·â½èÍý



¡¡¿·¤·¤¤³Ø½¬ÆâÍƤϡ¢°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£

¡¡¡¦¥é¥à¥À¼°¤Ë¤è¤ë¥×¥í¥Ñ¥Æ¥£¤Îµ­½ÒÊýË¡
¡¡¡¦¥·¥ó¥°¥ë¥È¥ó¡¦¥Ç¥¶¥¤¥ó¥Ñ¥¿¡¼¥ó¤Ë¤è¤ë¥¯¥é¥¹¤Î±¿ÍÑÊýË¡
¡¡¡¦DontDestroyOnLoad ¥á¥½¥Ã¥É



£²£°¡¥¾ã³²Êª¤Î¹¶·â½èÍý

£±¡¥Àß·×


¡¡Á°²ó¤Î¼ê½ç¤Þ¤Ç¤Ç¼ÂÁõ¤·¤Æ¤¤¤ë¡¢¥×¥ì¥¤¥ä¡¼¤Î¸½ºß¤Î¾õÂÖ¤ÎÀ©¸æ½èÍý¤È¹¶·â½èÍý¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£
¤¹¤Ù¤Æ PlayerController ¥¹¥¯¥ê¥×¥ÈÆâ¤ÇÀ©¸æ¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£


£±¡¥Update ¥á¥½¥Ã¥ÉÆâ¤Ë½èÍý¤òÄɲä·¡¢PlayerState ¤¬ Move °Ê³°¤Î¾õÂ֤Ǥϥ᥽¥Ã¥ÉÆâ¤Î½èÍý(°ÜÆ°ÍѤΥ­¡¼ÆþÎϽèÍý¤Ê¤É)¤¬¼Â¹Ô¤µ¤ì¤Ê¤¤¤è¤¦¤ËÄä»ß¤¹¤ëÀ©¸æ½èÍý¤òÄɲ乤ë
¡¡¡¡¡¡¢­
£²¡¥FixedUpdate ¥á¥½¥Ã¥ÉÆâ¤Ë½èÍý¤òÄɲä·¡¢PlayerState¤¬ Move°Ê³°¤Î¾õÂ֤Ǥϥ᥽¥Ã¥ÉÆâ¤Î½èÍý(°ÜÆ°½èÍý¤Ê¤É)¤¬¼Â¹Ô¤µ¤ì¤Ê¤¤¤è¤¦¤ËÄä»ß¤¹¤ëÀ©¸æ½èÍý¤òÄɲ乤ë
¡¡¡¡¡¡¢­
£³¡¥AutoBattle ¥á¥½¥Ã¥ÉÆâ¤Î½èÍý¤òÄɲä·¡¢¥Ð¥È¥ë¤Î³«»Ï¤Ë¹ç¤µ¤»¤Æ PlayerState ¤ò Battle_Before ¤ËÀÚ¤êÂؤ¨¤ë¡£¤³¤Î¾õÂ֤δ֡¢¥×¥ì¥¤¥ä¡¼¤Ï¹¶·â¤ò·«¤êÊÖ¤¹¤è¤¦¤ËÀ©¸æ¤¹¤ë
¡¡¡¡¾ã³²Êª¤Î Hp ¤¬ 0 °Ê²¼¤Ë¤Ê¤Ã¤¿¤é PlayerState ¤ò Result ¤ËÀÚ¤êÂؤ¨¤ë¡£¤³¤Î¾õÂ֤ˤʤ뤳¤È¤Ç¥×¥ì¥¤¥ä¡¼¤Ï¹¶·â¤ò½ªÎ»¤·¡¢¥Ð¥È¥ë¸å¤Î½èÍý¤Ë°Ü¹Ô¤¹¤ë
¡¡¡¡¤½¤Î¸å¡¢ºÆÅÙ PlayerState ¤ò Move ¤ËÀÚ¤êÂؤ¨¤ë
¡¡¡¡¡¡¢­
£´¡¥PlayerState ¤¬ Move ¤Ë¤Ê¤Ã¤¿¤Î¤Ç¡¢Ää»ß¤·¤Æ¤¤¤¿ Update ¥á¥½¥Ã¥É¤È FixedUpdate ¥á¥½¥Ã¥ÉÆâ¤Î½èÍý¤¬Æ°¤­»Ï¤á¤ë
¡¡¡¡¡¡¢­
£µ¡¥¤³¤ì¤ò·«¤êÊÖ¤¹

¡¡¤³¤Î¤¦¤Á¤Î¡¢¡Ú£³¡Û¤Î½èÍý¤Ë¡¢¾ã³²ÊªÂ¦¤Î¹¶·â¤Î½èÍý¤òÄɲä·¤Þ¤¹¡£
¥×¥ì¥¤¥ä¡¼¤Î¹¶·â ¢ª ¾ã³²Êª¤Î¹¶·â ¢ª ¥×¥ì¥¤¥ä¡¼¤Î¹¶·â¤È¤¤¤¦¤è¤¦¤Ë¡¢¤¤¤º¤ì¤«¤Î Hp ¤ÎÃͤ¬ 0 ¤Ë¤Ê¤ë¤Þ¤Ç¡¢¡Ú£³¡Û¤Î½èÍý¤ò¸ò¸ß¤Ë·«¤êÊÖ¤¹¤è¤¦¤Ë½èÍý¤ò½¤Àµ¤·¤Þ¤¹¡£

¡¡¤É¤Î¤è¤¦¤Ê½èÍý¤òÄɲ䷤Ƥ¤¤±¤Ð¤¤¤¤¤Î¤«¡¢¤Þ¤º¤Ï¹Í¤¨¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£

¡¡¤Ê¤ªº£²ó¤Ï¡¢¾ï¤Ë¥×¥ì¥¤¥ä¡¼¤Î¹¶·â¤«¤é»Ï¤Þ¤ë¤è¤¦¤Ë¼ÂÁõ¤·¤Þ¤¹¤¬¡¢Î㤨¤Ð¡¢ÉÒ¾¹À­¤Î¤è¤¦¤ÊÃͤòÁÐÊý¤ËÀßÄꤹ¤ë¤³¤È¤Ç¡¢
ÉÒ¾¹À­¤Î¹â¤¤Êý¤«¤é¹¶·â¤ò»Ï¤á¤ë¡¢¤È¤¤¤Ã¤¿½èÍý¤ËÊѹ¹¤·¤Æ¤¤¤¯¤³¤È¤â²Äǽ¤Ç¤¹¡£


£²¡¥ObstacleBase ¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤¹¤ë


¡¡Á°²ó¤Ë°ú¤­Â³¤­¡¢º£Å٤Ͼ㳲ʪ¤Ë¹¶·âÎϤγµÇ°¤òÍ¿¤¨¤Þ¤¹¡£¹Í¤¨Êý¤Ï Hp ÊÑ¿ô¤ÎºÝ¤ÈƱ¤¸¤Ç¤¹¡£

¡¡º£²ó¤Ï attackPower ¤È¤¤¤¦Ì¾Á°¤Î int ·¿¤ÎÊÑ¿ô¤òºîÀ®¤·¡¢¤³¤ÎÃͤò¾ã³²Êª¤Î¹¶·âÎϤȤ·¤ÆÍøÍѤ·¤Þ¤¹¡£
ÊÑ¿ô¤Î̾Á°¤ÏǤ°Õ¤Ç¤¹¤¬¡¢¤½¤ÎÊÑ¿ô¤ò¥×¥í¥°¥é¥àÆâ¤Ë¤ª¤¤¤Æ¡¢¤É¤¦¤¤¤Ã¤¿Ìò³ä¤È¤·¤ÆÍøÍѤ¹¤ë¤«¤òÀ߷פ·¤¿¾å¤Ç̾¾Î¤ò¹Í¤¨¤ë¤Èʬ¤«¤ê¤ä¤¹¤¯¤Ê¤ê¤Þ¤¹¡£

¡¡º£²ó¤â attackPower ÊÑ¿ô¤Ï private ½¤¾þ»Ò¤È¤·¤Æ³°Éô¤Î¥¯¥é¥¹¤«¤é¤ÏľÀÜ¥¢¥¯¥»¥¹¤Ç¤­¤Ê¤¤¾õÂ֤ˤ·¤Æ¤ª¤­¤Þ¤¹¡£
Âå¤ï¤ê¤Ë¥×¥í¥Ñ¥Æ¥£¤òºîÀ®¤·¡¢¥×¥í¥Ñ¥Æ¥£¤òÄ̤¸¤Æ¡¢attackPower ÊÑ¿ô¤Ø¤Î¥¢¥¯¥»¥¹¤ò¹Ô¤¦¤è¤¦¤ËÀ߷פ·¤Þ¤¹¡£

¡¡¤¿¤À¤·¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤è¤ê¡¢ÃͤòǤ°Õ¤ËÆþÎÏ¡¦Êѹ¹¡¦³Îǧ¤Ç¤­¤ë¤è¤¦¤Ë¤·¤Æ¤ª¤¯¤¿¤á¡¢hp ÊÑ¿ô¤ÈƱ¤¸¤è¤¦¤Ë SerializeField °À­¤ò°ì»þŪ¤ËÉÕÍ¿¤·¤Æ¤ª¤­¤Þ¤¹¡£
¤³¤¦¤¹¤ë¤³¤È¤Ë¤è¤ê¡¢¥Ç¥Ð¥Ã¥°¤ò¹Ô¤¤¤ä¤¹¤¯¤Ê¤ê¤Þ¤¹¡£
Àµ¼°¤Ê±¿ÍѤ¬»Ï¤Þ¤Ã¤¿¤é¡¢SerializeField °À­¤Ïºï½ü¤·¡¢private ½¤¾þ»Ò¤Î¤ß¤ÎÊÑ¿ô¤È¤·¤Þ¤¹¡£


ObstacleBase.cs

¡¡<=¡¡¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤­¤Þ¤¹¡£


¡¡¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤¿¤é¡¢¥»¡¼¥Ö¤ò¹Ô¤¤¤Þ¤¹¡£



¡¡¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤¿¤Î¤Ç¡¢¤³¤Î¥¹¥¯¥ê¥×¥È¤¬¥¢¥¿¥Ã¥Á¤µ¤ì¤Æ¤¤¤ë¾ã³²Êª¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¥Ò¥¨¥é¥ë¥­¡¼¤ÇÁªÂò¤·¤Æ³Îǧ¤·¤Þ¤¹¡£

¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤è¤ê ObstacleBase ¥¹¥¯¥ê¥×¥È¤ò³Îǧ¤¹¤ë¤È¡¢AttackPower ÊÑ¿ô¤¬Äɲ䵤ì¤Æ¤¤¤Þ¤¹¡£
½é´üÃÍ¤Ï 0 ¤Ç¤¹¤Î¤Ç¡¢¤Þ¤º¤Ï 1 ¤ËÀßÄꤷ¤Æ¤¯¤À¤µ¤¤¡£¤³¤ì¤¬¡¢¤³¤Î¾ã³²Êª¤Î¹¶·âÎϤǤ¹¡£


¡ã¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü¡ä



¡¡º£²ó¤Î¼ÂÁõ¤Ç¤ÏËɸæÎϤγµÇ°¤¬¤Ê¤¤¤¿¤á¡¢¤³¤Î¾ã³²Êª¤Î¹¶·âÎϤÎÃÍʬ¤ò¡¢¥×¥ì¥¤¥ä¡¼¤Î Hp ¤ÎÃͤ«¤é¸º¾¯¤µ¤»¤Þ¤¹¡£


£³¡¥¡ã¥é¥à¥À¼°¤Ë¤è¤ë¥×¥í¥Ñ¥Æ¥£¤Îµ­½ÒÊýË¡¡ä


¡¡¥é¥à¥À¼°¤Ë¤è¤ëµ­½Ò¤Ï¥×¥í¥Ñ¥Æ¥£¤Ë¤Ä¤¤¤Æ¤âÍøÍѤ¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£


¡ãÄ̾ï¤Î¥×¥í¥Ñ¥Æ¥£¤Î½ñ¼°¤Î°ìÎã¡ä
¡¡¡¡/// <summary>
    /// hp ¤Î¥×¥í¥Ñ¥Æ¥£
    /// </summary>
    public int Hp
    {
        get {
            return hp;
        }
        set {
            hp = value;
        } 
    }


¡ã¥é¥à¥À¼°¤Ë¤è¤ë¥×¥í¥Ñ¥Æ¥£¤Îµ­½ÒÊýË¡¡ä
¡¡// attackPower ÊÑ¿ô¤Î¥×¥í¥Ñ¥Æ¥£
  public int AttackPower { get => attackPower; set => attackPower = value; }

¡¡get Éôʬ¤Ë¤Ä¤¤¤Æ¤Ï return ¤ò¾Êά¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

¡¡Ãí°ÕÅÀ¤È¤·¤Æ¤Ï¡¢¥×¥í¥Ñ¥Æ¥£¤Ç¥é¥à¥À¼°¤Ë¤Ç¤­¤ë¤Î¤Ï£±¹Ôʬ¤À¤±¤Ç¤¹¡£
¤½¤Î¤¿¤á¡¢Î㤨¤Ð set Æâ¤Ë£²¹Ô°Ê¾å¤Î½èÍý¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¥é¥à¥À¼°¤Ç¤Îµ­½Ò¤Ï¤Ç¤­¤Þ¤»¤ó¡£


£´¡¥UserDataManager ¥¹¥¯¥ê¥×¥È¤òºîÀ®¤¹¤ë


¡¡¾ã³²Êª¤«¤é¤Î¹¶·â½èÍý¤òºîÀ®¤¹¤ë¤Ë¤¢¤¿¤ê¡¢º£Å٤ϥץ쥤¥ä¡¼¤Î Hp ¤ÎÃͤâ´ÉÍý¤¬É¬Íפˤʤê¤Þ¤¹¡£
¤³¤Î¾ðÊó¤Ï PlayerController ¥¹¥¯¥ê¥×¥È¤ËľÀÜ»ý¤¿¤»¤º¤Ë¡¢ÀìÍѤΥ¯¥é¥¹¤ò¥¹¥¯¥ê¥×¥È¤ÇºîÀ®¤·¤Æ¡¢¤½¤Á¤é¤Ç´ÉÍý¤ò¹Ô¤¤¤Þ¤¹¡£

¡¡º£¸å¡¢Hp °Ê³°¤Ë¤â¥×¥ì¥¤¥ä¡¼¤Î¾ðÊó¤¬Áý¤¨¤Æ¤¤¤¯¤³¤È¤òǰƬ¤ËÃÖ¤­¡¢
¤³¤Î¥¯¥é¥¹¤Ï¥·¥ó¥°¥ë¥È¥ó¤È¤¤¤¦¥Ç¥¶¥¤¥ó¥Ñ¥¿¡¼¥ó¤ÇºîÀ®¤ò¤·¤Æ¤ª¤­¤Þ¤¹¡£


UserDataManager.cs

<= ¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤­¤Þ¤¹


¡¡¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤¿¤é¥»¡¼¥Ö¤·¤Þ¤¹¡£


£µ¡¥¡ã¥·¥ó¥°¥ë¥È¥ó¥Ç¥¶¥¤¥ó¥Ñ¥¿¡¼¥ó¤Ë¤è¤ë¥¯¥é¥¹¤ÎºîÀ®¡ä


¡¡¥·¥ó¥°¥ë¥È¥ó¤È¤Ï¡¢¿ô¿¤¯¤¢¤ë¥Ç¥¶¥¤¥ó¥Ñ¥¿¡¼¥ó¤Î£±¤Ä¤Ç¤¹¡£
¤½¤Î¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤¬É¬¤º£±¤Ä¤Ç¤¢¤ë¤³¤È¤òÊݾڤ¹¤ë¥Ç¥¶¥¤¥ó¥Ñ¥¿¡¼¥ó¤Î¤³¤È¤ò¸À¤¤¤Þ¤¹¡£

¡¡UserDataManager ¥¯¥é¥¹¤Ç¤Ï¡¢¤³¤Î¥·¥ó¥°¥ë¥È¥ó¤òºÎÍѤ·¤Æ¤¤¤Þ¤¹¡£
¤Ä¤Þ¤ê¡¢¥²¡¼¥àÃæ¤òÄ̤¸¤Æ¡¢¤³¤Î UserDataManager ¥¯¥é¥¹¤¬£±¤Ä¤·¤«Â¸ºß¤Ç¤­¤Ê¤¤¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¼ÂÁõÎã¤ÏÊ£¿ô¤¢¤ê¤Þ¤¹¤¬¡¢°ìÈÖÆɤߤ䤹¤¤Êý¼°¤Çµ­½Ò¤·¤Æ¤¤¤Þ¤¹¡£



¡ã¥·¥ó¥°¥ë¥È¥ó¥Ç¥¶¥¤¥ó¥Ñ¥¿¡¼¥ó¤Î¥¯¥é¥¹¤ÎºîÀ®ÊýË¡¡ä
    public static UserDataManager instance;¡¡¡¡// ¥¯¥é¥¹Ì¾¤ÈƱ̾¤Î·¿¤ò static ¤ÇÀë¸À¤¹¤ë

    private void Awake() {
        if (instance == null) {
            instance = this;
            DontDestroyOnLoad(gameObject);
        } else {
            Destroy(gameObject);
        }
    }



¡¡¥Ý¥¤¥ó¥È¤Ï¡¢¼«Ê¬¼«¿È¤Î UserDataManager ·¿¤ò static ½¤¾þ»ÒÉÕ¤­¤Î instance ÊÑ¿ô¤È¤·¤ÆÀë¸À¤·¤Æ¤¤¤ë¤³¤È¤Ç¤¹¡£
¤³¤Î instance ÊÑ¿ô¤¬ UserDataManager ¥¯¥é¥¹¼«¿È¤¬ÂåÆþ¤µ¤ì¤¿¾ðÊó¤È¤·¤ÆÍøÍѤ¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£

¡¡Awake ¥á¥½¥Ã¥É¤òÍøÍѤ·¤Æ¡¢instance ÊÑ¿ô¤¬ null (¶õ¤Ã¤Ý) ¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢UserDataManager ¥¯¥é¥¹(this)¤òÂåÆþ¤·¤Þ¤¹¡£
¼¡¤Î DontDestroyOnLoad ¥á¥½¥Ã¥É¤Ï Unity ¤¬ÍÑ°Õ¤·¤Æ¤¤¤ë¥á¥½¥Ã¥É¤Ç¡¢°ú¿ô¤Ë»ØÄꤵ¤ì¤¿¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ï¥·¡¼¥óÁ«°Ü¤ò¤·¤Æ¤âÇ˲õ¤µ¤ì¤Æ¤Ê¤¤¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤Ê¤ê¤Þ¤¹¡£
¤³¤Î DontDestroyOnLoad ¥á¥½¥Ã¥É¤Ï¥·¥ó¥°¥ë¥È¥ó¥Ç¥¶¥¤¥ó¥Ñ¥¿¡¼¥ó¤Ë¤¹¤ëºÝ¤Ë°ì½ï¤ËÍѤ¤¤é¤ì¤ë¤³¤È¤¬Â¿¤¤¤Ç¤¹¡£

¡¡¤½¤·¤Æ instance ÊÑ¿ô¤¬ null ¤Ç¤Ï¤Ê¤¤¾ì¹ç¡¢¤Ä¤Þ¤ê¡¢£²¤ÄÌܰʹߤÎÊ£¿ô¤Î UserDataManager ¥¯¥é¥¹¤¬Â¸ºß¤¹¤ë¾ì¹ç¤Ë¤Ï¡¢¤½¤Î UserDataManager ¥¯¥é¥¹¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò Destroy ¤·¤Þ¤¹¡£
¤³¤Î¼ê½ç¤Ë¤è¤ê¡¢UserDataManager ¥¯¥é¥¹¤¬¥¢¥¿¥Ã¥Á¤µ¤ì¤Æ¤¤¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬¾ï¤Ë¥Ò¥¨¥é¥ë¥­¡¼¾å¤Ë£±¤Ä¤·¤«Â¸ºß¤·¤Ê¤¤¾õÂÖ¤òºî¤ê½Ð¤·¤Æ¤¤¤Þ¤¹¡£

¡¡¤³¤Î¥·¥ó¥°¥ë¥È¥ó¤Ë¤è¤Ã¤Æ¥¤¥ó¥¹¥¿¥ó¥¹¤¬£±¤Ä¤«À¸À®¤µ¤ì¤Ê¤¤¤³¤È¤¬Êݾڤµ¤ì¤Þ¤¹¤Î¤Ç¡¢
µÕÀâŪ¤Ë¹Í¤¨¤ë¤È¡¢¤³¤Î UserDataManager ¥¯¥é¥¹¤Ø¤Î»²¾È¤Ï¡¢¤¤¤º¤ì¤Î¥¯¥é¥¹¤«¤é¤Ç¤¢¤Ã¤Æ¤âÊÑ¿ô¤ò²ð¤µ¤º¤Ë»²¾È¤ò¹Ô¤¨¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£



¡¡Î㤨¤Ð¡¢NonPlayerCharacter ¤È¤¤¤¦¥¯¥é¥¹¤¬¤¢¤ê¡¢¤½¤Î NonPlayerCharacter ¥¯¥é¥¹¤ò»ý¤Ä¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬£µ¤Ä¤¢¤Ã¤¿¾ì¹ç¡¢
¡Ö¤É¤Î¡×NonPlayerCharacter ¥¯¥é¥¹¤Ç¤¢¤ë¤«¤ò³ÎÄê¤Ç¤­¤Ê¤¤¤È¡¢ÂоݤȤʤë NonPlayerCharacter ¥¯¥é¥¹¤Ø¤Ï»²¾È¤Ç¤­¤Þ¤»¤ó¡£
¤½¤Î¤¿¤á¡¢NonPlayerCharacter ·¿¤ÎÊÑ¿ô¤òÍÑ°Õ¤·¤Æ¡¢¤½¤ÎÊÑ¿ô¤Ø»²¾È¤·¤¿¤¤ NonPlayerCharacter ¥¯¥é¥¹¤òÂåÆþ¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¡¢
¤Ï¤¸¤á¤Æ NonPlayerCharacter ¥¯¥é¥¹¤Î¾ðÊó¤ò°·¤¦¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£¤³¤ì¤¬¾ðÊó¤ò°·¤¦ºÝ¤Î´ðËÜŪ¤Ê½èÍý¤Ë¤Ê¤ê¤Þ¤¹¡£

¡¡¤Ç¤¹¤¬¥·¥ó¥°¥ë¥È¥ó¤Ç¤¢¤ë UserDataManager ¥¯¥é¥¹¤Î¾ì¹ç¤Ë¤Ï¡¢¤³¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤Ï¾ï¤Ë£±¤Ä¤·¤«¤Ê¤¤¤³¤È¤¬Êݾڤµ¤ì¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢
¡Ö¤É¤Î¡×¤È¤¤¤¦»ØÄê¤ÎÉôʬ¤¬ÉÔÍפˤʤê¤Þ¤¹¡£¤è¤Ã¤Æ¥¯¥é¥¹¤ÎÆÃÄ꤬¤Ç¤­¤Æ¤¤¤ë¤¿¤á¡¢ÊÑ¿ô¤Ø¤ÎÂåÆþ¤¬ÉÔÍפˤʤê¤Þ¤¹¡£
UserDataManager ¤È¤¤¤¦»ØÄê¤Ï¤¹¤Ê¤ï¤Á¡¢¼«Æ°Åª¤Ë¤¿¤À£±¤Ä¤Î UserDataManager ¥¯¥é¥¹¤Î»²¾È¤¬¹Ô¤ï¤ì¤ë¤³¤È¤Ë¤Ê¤ë¤¿¤á¤Ç¤¹¡£

¡¡¤³¤Îµ¡Ç½¤òÍøÍѤ·¤Æ UserDataManager ¥¯¥é¥¹¤òºîÀ®¤·¤Æ¤ª¤¯¤³¤È¤Ç¡¢¤É¤Î¥¯¥é¥¹¤«¤é¤Ç¤â»²¾È¤·¤ä¤¹¤¤À߷פˤ·¤Æ¤ª¤­¤Þ¤¹¡£


£¶¡¥¡ãDontDestroyOnLoad ¥á¥½¥Ã¥É¡ä


¡¡¿·¤·¤¤¥·¡¼¥ó¤ò¥í¡¼¥É¤·¤ÆÁ«°Ü¤ò¤¹¤ë¤È¤­¤Ë¡¢°ú¿ô¤Ç»ØÄꤷ¤Æ¤¤¤ëÂоݤΥ²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤Ä¤¤¤Æ¤ÏÇË´þ¤µ¤ì¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¥á¥½¥Ã¥É¤Ç¤¹¡£
¤½¤Î¤¿¤á¼¡¤Î¥·¡¼¥ó¤ËÁ«°Ü¤·¤Æ¤â¡¢¤³¤Î¥¹¥¯¥ê¥×¥È¤¬¥¢¥¿¥Ã¥Á¤µ¤ì¤Æ¤¤¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ÏÁ°¤Î¥·¡¼¥ó¤«¤éÇË´þ¤µ¤ì¤º¤Ë»Ä¤ê³¤±¤Þ¤¹¡£

¡¡Â¿¤¯¤Î¾ì¹ç¡¢º£²ó¤Î¤è¤¦¤Ë¥·¥ó¥°¥ë¥È¥ó¥¯¥é¥¹¤Ç°ì½ï¤ËÍøÍѤµ¤ì¡¢¥¹¥¯¥ê¥×¥È¤¬¥¢¥¿¥Ã¥Á¤µ¤ì¤Æ¤¤¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¼«¿È¤òÂоݤ˼è¤ê¤Þ¤¹¡£
(¥¢¥¿¥Ã¥Á¤µ¤ì¤Æ¤¤¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬ÇË´þ¤µ¤ì¤Ê¤¯¤Ê¤ë)

  DontDestroyOnLoad(gameObject);

¡¡¤Ê¤ª¡¢¤³¤Î DontDestroyOnLoad ¥á¥½¥Ã¥É¤Î°ú¿ô¤ÇÂоݤȤʤäƤ¤¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ï¡¢¥²¡¼¥à¼Â¹Ô»þ¡¢DontDestroyOnLoad ¥·¡¼¥ó¤¬ºîÀ®¤µ¤ì¤Þ¤¹¡£
¥Ò¥¨¥é¥ë¥­¡¼¤Ë¤âÊ̤Υ·¡¼¥ó¤Î¾ðÊó¤È¤·¤Æɽ¼¨¤µ¤ì¡¢Ä̾ï¤ÎÇË´þ¤µ¤ì¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤È¤Ï¡¢´ÉÍý¤¬Ê̤ˤʤäƤ¤¤ë¤³¤È¤ò¸«Ê¬¤±¤é¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£


¥Ò¥¨¥é¥ë¥­¡¼²èÁü



»²¹Í¥µ¥¤¥È¡¡
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
Object.DontDestroyOnLoad
https://docs.unity3d.com/ja/current/ScriptReferenc...


£·¡¥UserDataManager ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤·¡¢UserDataManager ¥¹¥¯¥ê¥×¥È¤ò¥¢¥¿¥Ã¥Á¤·¡¢ÀßÄê¤ò¹Ô¤¦


¡¡¥Ò¥¨¥é¥ë¥­¡¼¤Î¶õ¤¤¤Æ¤¤¤ë¾ì½ê¤Ç±¦¥¯¥ê¥Ã¥¯¤ò¤·¤Æ¥á¥Ë¥å¡¼¤ò³«¤­¡¢CreateEmpty ¤òÁªÂò¤·¡¢¿·¤·¤¤¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤·¤Þ¤¹¡£
̾Á°¤ò UserDataManager ¤ËÊѹ¹¤·¡¢Àè¤Û¤ÉºîÀ®¤·¤¿¡¢Æ±Ì¾¤Î UserDataManager ¥¹¥¯¥ê¥×¥È¤ò¥¢¥¿¥Ã¥Á¤·¤Æ¤¯¤À¤µ¤¤¡£

¡¡¥¢¥¿¥Ã¥Á¤¬Àµ¾ï¤Ë¹Ô¤ï¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤ò³Îǧ¤·¤¿¾å¤Ç¡¢Hp ÊÑ¿ô¤ËÃͤòÀßÄꤷ¤Æ¤¯¤À¤µ¤¤¡£


¡ã¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü¡ä



¡¡°Ê¾å¤ÇÀßÄê¤Ï´°Î»¤Ç¤¹¡£


£¸¡¥PlayerController ¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤¹¤ë


¡¡AutoBattle ¥á¥½¥Ã¥ÉÆâ¤Ë¾ã³²Êª¤Ë¤è¤ë¹¶·â¤Î½èÍý¤òÄɲä·¡¢¥×¥ì¥¤¥ä¡¼¤Î¹¶·â¤È¾ã³²Êª¤Î¹¶·â¤¬¸ò¸ß¤ËȯÀ¸¤¹¤ë¤è¤¦¤ËÀ©¸æ¤ò¹Ô¤¤¤Þ¤¹¡£

¡¡¤³¤ÎÀ©¸æ¤Ë¤è¤ê¡¢¤¤¤º¤ì¤«¤Î Hp ¤ÎÃͤ¬ 0 °Ê²¼¤Ë¤Ê¤ë¤Þ¤Ç¹¶·â¤ò·«¤êÊÖ¤¹½èÍý¤ò´°À®¤µ¤»¤Þ¤¹¡£


PlayerController.cs

¡¡<=¡¡¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤­¤Þ¤¹¡£


¡¡¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤¿¤é¥»¡¼¥Ö¤ò¤·¤Þ¤¹¡£


£¹¡¥¥²¡¼¥à¤ò¼Â¹Ô¤·¤ÆÆ°ºî¤ò³Îǧ¤¹¤ë


¡¡¿·¤·¤¤µ¡Ç½¤ò¤¿¤¯¤µ¤ó¼ÂÁõ¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¤½¤ì¤é¤ÎÉü½¬¤ò¹Ô¤¤¤Ê¤¬¤é¡¢½èÍý¤ÎÍý²ò¤ò¿¼¤á¤Æ¤¤¤­¤Þ¤·¤ç¤¦¡£
½èÍý¤¬Íý²ò¤Ç¤­¤¿¤é¡¢¥²¡¼¥à¤ò¼Â¹Ô¤·¤Æ¥Ç¥Ð¥Ã¥°¤ò¹Ô¤¤¤Þ¤¹¡£

¡¡ÁÐÊý¤Î¹¶·â½èÍý¤ò¼ÂÁõ¤·¤Þ¤·¤¿¤Î¤Ç¡¢º£²ó¤Î Console ¥Ó¥å¡¼¤Ë¤Ï¡¢
¡Ú¾ã³²Êª¤Î»Ä¤ê HP : ¡Û¡¢¡Ú¥×¥ì¥¤¥ä¡¼¤Î»Ä¤ê HP : ¡Û¤È¤¤¤¦·Á¤Ç¡¢¸ò¸ß¤Ë¹¶·â¤Î½èÍý¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£

¡¡¤Þ¤¿º£²ó¤Ï¡¢¥×¥ì¥¤¥ä¡¼¤Î Hp ¤¬ 0 ¤Ë¤Ê¤Ã¤¿¤é Console ¥Ó¥å¡¼¤Ë¥²¡¼¥à¥ª¡¼¥Ð¡¼¤Èɽ¼¨¤µ¤ì¤ë¤è¤¦¤Ë Debug.Log ¥á¥½¥Ã¥É¤òÍÑ°Õ¤·¤Æ¤¤¤Þ¤¹¡£
¤¤¤Þ¤Þ¤Ç¤ÈƱ¤¸¤Ë¤è¤¦¤Ë¾ã³²Êª¤¬Ç˲õ¤µ¤ì¤Æ¡¢ºÆÅÙ¡¢¥×¥ì¥¤¥ä¡¼¤Î°ÜÆ°¤¬²Äǽ¤Ë¤Ê¤ë¤³¤È¤ò³Îǧ¤¹¤ë¤È¤È¤â¤Ë¡¢
¥×¥ì¥¤¥ä¡¼¤Î Hp ¤ÎÃͤˤĤ¤¤Æ¤â¥Ç¥Ð¥Ã¥°¤ò¹Ô¤¤¡¢¥²¡¼¥à¥ª¡¼¥Ð¡¼É½¼¨¤¬ Console ¥Ó¥å¡¼¤Ëɽ¼¨¤µ¤ì¤ë¤«¤â³Îǧ¤â¤·¤Æ¤¯¤À¤µ¤¤¡£

¡¡¤³¤Î¤è¤¦¤Ë¡¢¼ÂºÝ¤Ë¥Ç¥Ð¥Ã¥°¤ò³«»Ï¤¹¤ëÁ°¤Ë¡¢¤É¤¦¤¤¤Ã¤¿½èÍý¤Î·ë²Ì¤¬¹Í¤¨¤é¤ì¤ë¤«¤òÁÛÄꤷ¤¿¾å¤Ç
¹Í¤¨¤é¤ì¤ë¤¹¤Ù¤Æ¤Î·ë²Ì¤Ë¤Ä¤¤¤Æ½çÈ֤˳Îǧ¤ò¹Ô¤Ã¤Æ¤¤¤¯É¬Íפ¬¤¢¤ê¤Þ¤¹¡£

¡¡¥Ç¥Ð¥Ã¥°¤ò¹Ô¤¤¤ä¤¹¤¯¤¹¤ë¤¿¤á¡¢ÁÐÊý¤Î Hp ¤ÎÃͤϤɤÁ¤é¤â¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤è¤êÊѹ¹¤¬¤Ç¤­¤Þ¤¹¤Î¤Ç¡¢
¤³¤Îµ¡Ç½¤ò³èÍѤ·¤ÆÄ´À°¤·¡¢¥Ç¥Ð¥Ã¥°¤ò¹Ô¤Ã¤Æ¤¯¤À¤µ¤¤¡£


¡ã¥×¥ì¥¤¥ä¡¼¤Î¾¡Íø(¥×¥ì¥¤¥ä¡¼¤Î Hp ¤ò¾ã³²Êª¤Î Hp ¤è¤ê¤â¹â¤¯¤¹¤ë)¡ä



¡ã¾ã³²Êª¤Î¾¡Íø(¥×¥ì¥¤¥ä¡¼¤Î Hp ¤ò¾ã³²Êª¤Î Hp ¤è¤ê¤âÄ㤯¤¹¤ë)¡ä


¡¡
¡¡½èÍý¤òÍý²ò¤·¤Æ¤ª¤¯¤³¤È¤Ç¡¢¤µ¤é¤Ë¥Ç¥Ð¥Ã¥°¤ò¤¹¤ë¤Ù¤­ÅÀ¤¬¸«¤Ä¤«¤ê¤Þ¤¹¡£
¥×¥ì¥¤¥ä¡¼¤Î Hp ¤¬ 0 ¤Ë¤Ê¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢¥×¥ì¥¤¥ä¡¼¤Î¾õÂÖ(currentPlayerState ÊÑ¿ô)¤¬ Move ¤ËÀÚ¤êÂؤï¤é¤Ê¤¤(Âå¤ï¤ê¤Ë GameUp ¤Ë¤Ê¤ë)¤¿¤á¡¢
¤½¤Î¤Þ¤Þ°ÜÆ°¤¬½ÐÍè¤Ê¤¤¾õÂÖ¤¬·Ñ³¤µ¤ì¤Þ¤¹¡£

¡¡¤³¤Á¤é¤â¹ç¤ï¤»¤Æ³Îǧ¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£



¡¡°Ê¾å¤Ç¤³¤Î¼ê½ç¤Ï½ªÎ»¤Ç¤¹¡£

¡¡¼¡¤Ï¡¡¼ê½ç£±£´¡¡¡Ý¡Ý?¡¡¤Ç¤¹¡£

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

Menu


´ðÁÃ

µ»½Ñ/Ãμ±(¼ÂÁõÎã)

3D¥¢¥¯¥·¥ç¥ó¥²¡¼¥à

2D¤ª¤Ï¤¸¤­¥²¡¼¥à(ȯŸÊÔ)

2D¶¯À©²£¥¹¥¯¥í¡¼¥ë¥¢¥¯¥·¥ç¥ó(ȯŸÊÔ)

2D¥¿¥Ã¥×¥·¥å¡¼¥Æ¥£¥ó¥°(³ÈÄ¥ÊÔ)

¥ì¡¼¥¹¥²¡¼¥à(È´¿è)

2DÊüÃÖ¥²¡¼¥à(ȯŸÊÔ)

3D¥ì¡¼¥ë¥¬¥ó¥·¥å¡¼¥Æ¥£¥ó¥°(±þÍÑÊÔ)

3Dæ½Ð¥²¡¼¥à(È´¿è)

2D¥ê¥¢¥ë¥¿¥¤¥à¥¹¥È¥é¥Æ¥¸¡¼

3D¥¿¥Ã¥×¥¢¥¯¥·¥ç¥ó(NavMeshAgent »ÈÍÑ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥«¥¨¥ë¤Î°Ù¤Ë¡Á¡¢¥Ü¥³¥¹¥«¥¦¥©¡¼¥ºÉ÷)

VideoPlayer ¥¤¥Ù¥ó¥ÈϢư¤Î¼ÂÁõÎã

VideoPlayer ¥ê¥¹¥ÈÆ⤫¤é¥à¡¼¥Ó¡¼ºÆÀ¸¤Î¼ÂÁõÎã(ȯŸ)

AR ²èÁüÉÕ¤­¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®¤Î¼ÂÁõÎã

AR ¥ê¥¹¥ÈÆ⤫¤éÀ¸À®¤Î¼ÂÁõÎã(ȯŸ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥µ¥Ð¥¤¥Ð¡¼É÷)

private



¤³¤Î¥µ¥¤¥ÈÆâ¤ÎºîÉʤϥæ¥Ë¥Æ¥£¤Á¤ã¤ó¥é¥¤¥»¥ó¥¹¾ò¹à¤Î¸µ¤ËÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹