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

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

¼ê½ç£²£¶¡¡¡¼BGM¤ÎÀ©¸æ½èÍý¤Î¼ÂÁõ¡¼
£´£µ¡¥BGMÍѤΥª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤·¤ÆUnity¤Ë¥¤¥ó¥Ý¡¼¥È¤¹¤ë
£´£¶¡¥¥¹¥¯¥ê¥×¥È¤ò»È¤Ã¤Æ¡¢¾ìÌ̤˹ç¤ï¤»¤ÆBGM¤ò¼«Æ°Åª¤ËÀÚ¤êÂؤ¨¤ëÀ©¸æ½èÍý¤ò¼ÂÁõ¤¹¤ë(¥²¡¼¥àÃ梪¥¯¥ê¥¢)



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

¡¡¡¦enum ¤Î¥­¥ã¥¹¥È½èÍý¤òÍøÍѤ·¤ÆÇÛÎó¤ÎÍ×ÁÇÈÖ¹æ¤ò»ØÄꤹ¤ë
¡¡¡¦AudioSource.Play¥á¥½¥Ã¥É¡¢AudioSource.Stop¥á¥½¥Ã¥É¡¢AudioSource.clip ÊÑ¿ô



£´£µ¡¥BGMÍѤΥª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤·¤ÆUnity¤Ë¥¤¥ó¥Ý¡¼¥È¤¹¤ë

£±¡¥Àß·×


¡¡BGM¤òÌĤ餹¾ìÌÌ¡¦¥·¡¼¥ó¤ò¹Í¤¨¤Æ¡¢BGM¤òÍÑ°Õ¤·¤Þ¤¹¡£

¡¡¤Þ¤º¤Ï¤É¤Î¾ìÌÌ¡¦¥·¡¼¥ó¤ÇBGM¤òÌĤ餹¤«¤òÁÛÄꤷ¡¢¤½¤Î¼ïÎàʬ¤ÎBGM¤¬É¬Íפˤʤ뤳¤È¤òÇÄ°®¤·¤Þ¤¹¡£
º£²ó¤Ï¾ìÌ̤Ȥ·¤Æ¤Ï¡¢°Ê²¼¤Î£²¼ïÎà¤Ç¤¹¡£º¸Â¦¤¬ÁÛÄꤹ¤ë¥Õ¥¡¥¤¥ë̾¡¢±¦Â¦¤¬BGM¤òÌĤ餹¾ìÌ̤Ǥ¹¡£

¡¡£±¡¥Main       --  ¥²¡¼¥à¥×¥ì¥¤Ãæ
¡¡£²¡¥GameClear  --  ¥²¡¼¥à¥¯¥ê¥¢»þ¡¢¥ê¥¶¥ë¥Èɽ¼¨Ãæ


¡¡BGM¤òÌĤ餹¾ìÌ̤¬¸Ç¤Þ¤Ã¤¿¤é¡¢ÌµÎÁ¤Î²»³Ú¥µ¥¤¥È¤ä»ý¤Ã¤Æ¤¤¤ë²»¸»¤Ê¤É¤òUnity¤Ø¥¤¥ó¥Ý¡¼¥È¤·¤Æ¡¢¥²¡¼¥àÆâ¤Ç²»³Ú¤òÌĤ餹¤¿¤á¤Î½àÈ÷¤ò¤·¤Þ¤¹¡£


£²¡¥BGM¤òºÆÀ¸¤¹¤ë¾ìÌ̤ò¥¤¥á¡¼¥¸¤·¤Æ¡¢¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤òõ¤·¤Æ¥À¥¦¥ó¥í¡¼¥É¤¹¤ë


¡¡ÌµÎÁ¤Î²»¸»¥À¥¦¥ó¥í¡¼¥É¥µ¥¤¥È¤Ê¤É¤Ø¥¢¥¯¥»¥¹¤·¤Æ¡¢Æ¬¤ÎÃæ¤Ç¾ìÌ̤ò»×¤¤É⤫¤Ù¤Ê¤¬¤é¡¢¤É¤ó¤ÊBGM¤¬¤è¤¤¤«¡¢»ëÄ°¤·¤Ê¤¬¤é·è¤á¤Æ¤¤¤­¤Þ¤·¤ç¤¦¡£
Àè¤Û¤ÉÄ󼨤·¤¿¾ìÌ̤˹ç¤ï¤»¤Æ¡¢¹ç·×¤Ç£´¼ïÎà¤Î¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤òÍÑ°Õ¤ò¤·¤Æ¤¯¤À¤µ¤¤¡£

¡¡¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤Ï mp3 ¥Õ¥¡¥¤¥ë¤¬¥µ¥¤¥º¤â¾®¤µ¤¯²»¼Á¤â¤è¤¤¤¿¤á¡¢¤ª¤¹¤¹¤á¤Ç¤¹¡£
¤½¤Î¤Û¤«¤ÎUnity¤ÇºÆÀ¸²Äǽ¤Ê¥Õ¥¡¥¤¥ë¤Ë¤Ä¤¤¤Æ¤Ï¤³¤Á¤é¤ò³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£

Unity¸ø¼°¥Þ¥Ë¥å¥¢¥ë
¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë
https://docs.unity3d.com/ja/2018.4/Manual/AudioFil...

¡¡
¡¡¥À¥¦¥ó¥í¡¼¥É¤·¤¿¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤Ï¡¢¾åµ­¤Î¥ê¥¹¥È¤ò»²¹Í¤Ë¥Õ¥¡¥¤¥ë̾¤òÊѹ¹¤·¤Æ¤ª¤­¤Þ¤·¤ç¤¦¡£


£³¡¥¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤òUnity¤Ø¥¤¥ó¥Ý¡¼¥È¤¹¤ë


¡¡Unity¤Ø¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ò¥¤¥ó¥Ý¡¼¥È¤¹¤ëÊýË¡¤Ï¡¢²èÁü¥Õ¥¡¥¤¥ë¤ÈƱ¤¸¤Ç¤¹¡£
Unity¤Ø¥É¥é¥Ã¥°¥¢¥ó¥É¥É¥í¥Ã¥×¤·¤Æ¥Õ¥©¥ë¥À¤Ø°ÜÆ°¤¹¤ë¤³¤È¤Ç¥¤¥ó¥Ý¡¼¥È¤µ¤ì¤Þ¤¹¡£

¡¡»öÁ°¤Ë UnityÆâ¤Ë Audio ¥Õ¥©¥ë¥À¤òºîÀ®¤·¤Æ¤ª¤¤¤Æ¡¢¤½¤ÎÃæ¤Ø¥¤¥ó¥Ý¡¼¥È¤¹¤ë¤è¤¦¤Ë¤·¤Þ¤·¤ç¤¦¡£
º£²ó¤Ï Audio ¥Õ¥©¥ë¥ÀÆâ¤Ë BGM¡¡¥Õ¥©¥ë¥À¤È SE ¥Õ¥©¥ë¥À¤òºîÀ®¤·¡¢BGM ¥Õ¥©¥ë¥ÀÆâ¤ËÁ´¥Õ¥¡¥¤¥ë¤ò¥¤¥ó¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤¹¡£


Audio/BGM ¥Õ¥©¥ë¥À²èÁü



¡¡ÌµÎÁ¥µ¥¤¥È¤«¤é¥À¥¦¥ó¥í¡¼¥É¤·¤¿¾ì¹ç¤Ë¤Ï¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤¬°µ½Ì¤µ¤ì¤Æ¤¤¤ë²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É¬¤º²òÅà¤ò¹Ô¤Ã¤¿¾å¤ÇUnity¤Ø¥¤¥ó¥Ý¡¼¥È¤·¤Æ¤¯¤À¤µ¤¤¡£
²òÅव¤ì¤Æ¤¤¤Ê¤¤¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤Ï¥¤¥ó¥Ý¡¼¥È¤¬¹Ô¤¨¤Þ¤»¤ó¡£


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


£´£¶¡¥¥¹¥¯¥ê¥×¥È¤ò»È¤Ã¤Æ¡¢¾ìÌ̤˹ç¤ï¤»¤ÆBGM¤ò¼«Æ°Åª¤ËÀÚ¤êÂؤ¨¤ëÀ©¸æ½èÍý¤ò¼ÂÁõ¤¹¤ë(¥²¡¼¥àÃ梪¥¯¥ê¥¢)

£±¡¥Àß·×


¡¡À߷פȤ·¤Æ¤Ï¡¢¥«¥á¥é¤ÎÀ©¸æ½èÍý¤ÈƱ¤¸¤è¤¦¤Ê·Á¤Ë¤Ê¤ê¤Þ¤¹¡£
¥­¥ã¥é¤ÎÃå¿å¤Î¥¿¥¤¥ß¥ó¥°¤Ç¡¢ÍÑ°Õ¤·¤Æ¤ª¤¤¤¿ BGM ¤òÀÚ¤êÂؤ¨¤ë¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢BGM ¤òÊѹ¹¤¹¤ë¤è¤¦¤ËÀ©¸æ¤·¤Þ¤¹¡£

¡¡BGM À©¸æ¤Î¥¿¥¤¥ß¥ó¥°¤Ï£²²ó¤Ç¤¹¡£¥²¡¼¥à³«»Ï»þ¤Ë£±²ó¡¢¤½¤ì¤ÈÃå¿å»þ¤Ë£±²ó¤Ç¤¹¡£

¡¡¥²¡¼¥à³«»Ï»þ¤Ë¤Ï Main ÍѤΥª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ò»ØÄꤷ¤Æ¡¢¤½¤ì¤òºÆÀ¸¤¹¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£

¡¡Ãå¿å¡Ê¥²¡¼¥à¥¯¥ê¥¢¡Ë»þ¤Ë¤Ï GameClear ÍѤΥª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ò»ØÄꤷ¤Æ¡¢¤½¤ì¤òºÆÀ¸¤¹¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£

¡¡ºÆÀ¸¤¹¤ë¤¿¤á¤Î¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤Ï¥¹¥¯¥ê¥×¥ÈÆâ¤Ë»öÁ°¤ËÅÐÏ¿¤·¤Æ¤ª¤¤¤Æ¡¢¥²¡¼¥àÆâ¤ÇưŪ¤Ë AudioClip ¤òÊѹ¹¤·¤ÆºÆÀ¸¤¹¤ëBGM¤òÀÚ¤êÂؤ¨¤Þ¤¹¡£¡¡
¥×¥ì¥Õ¥¡¥Ö¤Ë¤Ê¤Ã¤Æ¤¤¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¥¤¥ó¥¹¥¿¥ó¥¹¤¹¤ë¾ì¹ç¤ÈƱ¤¸¼êË¡¤Ç¤¹¡£


£²¡¥AudioManager ¥¹¥¯¥ê¥×¥È¤òºîÀ®¤¹¤ë


¡¡AudioSource ·¿¤ÎÊÑ¿ô¤òÀë¸À¤·¤Æ¡¢AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤òÁàºî¤Ç¤­¤ë¤è¤¦¤Ë¤·¤Æ¤ª¤­¤Þ¤¹¡£
AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤òÁàºî¤Ç¤­¤ì¤Ð¡¢AudioClip ÊÑ¿ô¤ò»²¾È¤·¤ÆºÆÀ¸¤µ¤»¤ë¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤òÀÚ¤êÂؤ¨¤ë¤³¤È¤¬²Äǽ¤Ë¤Ê¤ê¤Þ¤¹¡£
¤Þ¤¿¡¢¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ÎºÆÀ¸¡¦Ää»ß¤ÎÌ¿Îá¤â AudioSource ¥¯¥é¥¹¤Î»ý¤Ä¥á¥½¥Ã¥É¤ÇÀ©¸æ¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¡¡¹ç¤ï¤»¤Æ¡¢AudioClip ·¿¤ÎÇÛÎóÊÑ¿ô¤ò SerializeField°À­¤ÇÀë¸À¤·¤Þ¤¹¡£¤½¤¦¤¹¤ë¤³¤È¤ÇÇÛÎóÊÑ¿ô¤ÎÃͤò¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤«¤é¥¢¥µ¥¤¥ó¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
AudioClip ·¿¤Ë¤Ï¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤òÅÐÏ¿¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¤Î¤Ç¡¢Àè¤Û¤É Unity ¤Ë¥¤¥ó¥Ý¡¼¥È¤·¤¿¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ò¤³¤³¤Ë»öÁ°¤ËÅÐÏ¿¤·¤Æ¤ª¤¤¤Æ
¤½¤ì¤ò¥²¡¼¥àÆâ¤Î¾ìÌ̤˹ç¤ï¤»¤Æ¡¢AudioSource ¤Î AudioClip ¤òº¹¤·Âؤ¨¤ë¤³¤È¤Ç¡¢ºÆÀ¸¤¹¤ë¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤òÊѹ¹¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

¡¡BGM¤Î¼ïÎà¤Ë¤Ä¤¤¤Æ¤Ï enum ¤Î BgmType ·¿¤òºîÀ®¤·¡¢»öÁ°¤Ë¤É¤Î¤è¤¦¤Ê¼ïÎब¤¢¤ë¤«¤òÅÐÏ¿¤·¤ÆÍøÍѤ¹¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
¤¤¤Þ¤Î¤È¤³¤í¤Ï Main ¤È GameClear ¤Î£²¤Ä¤ÎÎóµó»Ò¤òºîÀ®¤·¤ÆÅÐÏ¿¤·¤Æ¤ª¤­¤Þ¤¹¡£


AudioManager.cs

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



£³¡¥¡ãenum ¤Î¥­¥ã¥¹¥È½èÍý¤òÍøÍѤ·¤ÆÇÛÎó¤ÎÍ×ÁÇÈÖ¹æ¤ò»ØÄꤹ¤ë¡ä


¡¡enum ¤ÇºîÀ®¤·¤¿ BgmType ·¿¤Ç¤¹¤¬¡¢enum ¤ÏºîÀ®¤¹¤ë¤È¡¢¼«Æ°Åª¤Ë¡¢ÅÐÏ¿¤·¤¿Îóµó»Ò¤Î½çÈÖ¤Ë 0 ¤«¤éÈֹ椬ÆâÉô¾ðÊó¤È¤·¤ÆÍ¿¤¨¤é¤ì¤Þ¤¹¡£

  // BGM¤Î¼ïÎà¤òÅÐÏ¿
  public enum BgmType {
¡¡  ¡¡Main,          // ¼«Æ°Åª¤Ë 0 ¤¬³ä¤ê¿¶¤é¤ì¤Æ¤¤¤ë
      GameClear      // ¤³¤Á¤é¤âƱÍͤˡ¢1 ¤¬³ä¤ê¿¶¤é¤ì¤Æ¤¤¤ë
  }

¡¡¤³¤ÎÈÖ¹æ¤Ï int ·¿¤Ç¤¹¡£¤½¤Î¤¿¤á enum ¤ÎÎóµó»Ò¤Ï¡¢ÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë̾Á°¤Î¾¤Ë¡¢ÈÖ¹æ¤Î¾ðÊó¤òÍøÍѤ¹¤ë¤³¤È¤â½ÐÍè¤Þ¤¹¡£

¡¡Îóµó»Ò¤ò int ·¿¤ÎÈÖ¹æ¤È¤·¤ÆÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¥­¥ã¥¹¥È½èÍý¤ò¹Ô¤¤¤Þ¤¹¡£¥­¥ã¥¹¥È¤È¤Ï¡¢·¿¤òÊÑ´¹¤¹¤ë½èÍý¤Î¤³¤È¤Ç¤¹¡£
¤¹¤Ù¤Æ¤Î·¿Æ±»Î¤Ç¥­¥ã¥¹¥È¤¬¹Ô¤¨¤ë¤ï¤±¤Ç¤Ï¤Ê¤¯¡¢µö²Ä¤µ¤ì¤Æ¤¤¤ë·¿¤Î´Ö¤Ç¤Î¤ß¡¢¥­¥ã¥¹¥È¤¬¹Ô¤¨¤Þ¤¹¡£

¡¡eunm ¤Î BgmType ·¿¤ò int ·¿¤Ë¤¹¤ë·¿ÊÑ´¹¤Î½èÍý¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤ë½èÍý¤Ç¤¹¤Î¤Ç¡¢BgmType ·¿¤ò»ý¤ÄÎóµó»Ò¤ò int ·¿¤ËÊÑ´¹¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
¤³¤³¤Ç¤Ï°·¤¤¤Þ¤»¤ó¤¬¡¢È¿ÂФˡ¢int ·¿¤ò BgmType ·¿¤Ë¥­¥ã¥¹¥È¤·¤Æ¡¢Îóµó»Ò¤ËÊÑ´¹¤¹¤ë¤³¤È¤â½ÐÍè¤Þ¤¹¡£

¡ã¥­¥ã¥¹¥È½èÍý¡ä
  // ºÆÀ¸¤¹¤ëBGM¤òÀßÄꤹ¤ë
  audioSource.clip = bgms[(int)bgmType];

¡¡bgms ÇÛÎó¤ÎÍ×ÁÇÈÖ¹æ(¥¤¥ó¥Ç¥Ã¥¯¥¹)¤Î»ØÄê¤Ï int ·¿¤Ç¤·¤«»ØÄê¤Ç¤­¤Þ¤»¤ó¡£¤½¤Î¤¿¤á¡¢BgmType ·¿¤ò int ·¿¤Ë¥­¥ã¥¹¥È¤¹¤ë¤³¤È¤Ç
Main => 0¡¢GameClear => 1 ¤È¤¤¤¦·Á¤Ç·¿¤ÎÊÑ´¹¤ò¹Ô¤Ã¤Æ int ·¿¤Ë¤¹¤ë¤³¤È¤Ç¡¢Îóµó»Ò¤Ë¸«¹ç¤Ã¤¿Í×ÁÇÈÖ¹æ¤ò»ØÄꤹ¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

¡¡¤Ê¤¼¤³¤Î¤è¤¦¤Ê½èÍý¤ò¼ÂÁõ¤·¤Æ¤¤¤ë¤«¤òÊä­¤·¤Þ¤¹¡£

¡¡ÇÛÎó¤ÏÍ×ÁÇÈÖ¹æ¤Ç´ÉÍý¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¤¬¡¢BGM¤Î»ØÄê¤òÈÖ¹æ¤Ë¤·¤Æ¤·¤Þ¤¦¤È¡¢BGM¤Î¿ô¤¬Â¿¤¯¤Ê¤Ã¤¿¾ì¹ç¤ËÇÄ°®¤Ç¤­¤º´ÉÍýÉÔÁ´¤Ë¤Ê¤ê¤Þ¤¹¡£
º£²ó¤Ï2¼ïÎष¤«¤¢¤ê¤Þ¤»¤ó¤¬¡¢¤³¤ì¤¬20¼ïÎढ¤Ã¤¿¾ì¹ç¡¢bgms[11] ¤ÈÍ×ÁÇÈÖ¹æ¤ò»ØÄꤷ¤Æ¡¢¤½¤Î¶Ê¤¬¤É¤Î¾ìÌ̤ζʤ«¤òÆɤ߼è¤ë¤Î¤ÏÈó¾ï¤Ëº¤Æñ¤Ë¤Ê¤ê¤Þ¤¹¡£

¡¡¤½¤³¤Ç¡¢BGM¤Î»ØÄê¤Ï BgmType ·¿¤òÍøÍѤ¹¤ë¤³¤È¤Ç¡¢¤É¤Î¾ìÌ̤ζʤǤ¢¤ë¤«¤òÌÀ¼¨Åª¤Ë¤ï¤«¤ë¤è¤¦¤Ë¤·¤Æ¤ª¤­¡¢
¤½¤ì¤ò¼ÂºÝ¤Ë»ÈÍѤ¹¤ëºÝ¤Ë¥­¥ã¥¹¥È¤·¤ÆÍøÍѤ¹¤ë¤è¤¦¤Ë¤·¤Æ¤¤¤Þ¤¹¡£
¤³¤Î¤è¤¦¤Ë¤·¤Æ¤ª¤±¤Ð¡¢¥×¥í¥°¥é¥à¤òÆɤàÃʳ¬¤Ç¡¢BGM ¤È¤·¤Æ¤É¤ó¤Ê¼ïÎबÍøÍѤµ¤ì¤Æ¤¤¤ë¤«¤¹¤°¤ËÆɤ߼è¤ì¤ë¤¿¤á¡¢²ÄÆÉÀ­¤Î¹â¤¤¥³¡¼¥É¤Ë¤Ê¤ê¤Þ¤¹¡£

¡¡¤Þ¤¿¡¢BGM ¤Î»ØÄ꤬´Ö°ã¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¤âµ¤¤Å¤­¤ä¤¹¤¯¤Ê¤ê¤Þ¤¹¡£
Î㤨¤Ð¡¢¥²¡¼¥à¥ª¡¼¥Ð¡¼¤Î¾ìÌ̤ζʤλØÄ꤬ bgms[5] ¤Ç¤Ï¤ï¤«¤ê¤Þ¤»¤ó¤¬¡¢BgmType.Title ¤È½ñ¤¤¤Æ¤¢¤ì¤Ðµ¤¤Å¤¯¤³¤È¤¬½ÐÍè¤ë¤Ï¤º¤Ç¤¹¡£


£´¡¥¡ãAudioSource.Play¥á¥½¥Ã¥É¡¢AudioSource.Stop¥á¥½¥Ã¥É¡¢AudioSource.clip ÊÑ¿ô¡ä


¡¡AudioSource.Play¥á¥½¥Ã¥É¤òÍøÍѤ¹¤ë¤³¤È¤Ç¡¢AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î AudioClip ¤Ë¥¢¥µ¥¤¥ó¤µ¤ì¤Æ¤¤¤ë¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ò¥²¡¼¥àÆâ¤ÇºÆÀ¸¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

¡¡¤Þ¤¿¡¢AudioSource.Stop¥á¥½¥Ã¥É¤òÍøÍѤ¹¤ë¤³¤È¤Ç¡¢AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î AudioClip ¤Ë¥¢¥µ¥¤¥ó¤µ¤ì¤Æ¤¤¤ë¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ÎºÆÀ¸¤òÄä»ß¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

¡¡ºÆÀ¸¤µ¤ì¤ë¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤Ï¡¢ÂоݤΠAudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î AudioClip ¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤Ë¤Ê¤ê¤Þ¤¹¡£
¤³¤Á¤é¤Ï¥¹¥¯¥ê¥×¥È¤«¤é AudioSource.clip ÊÑ¿ô¤ò»²¾È¤¹¤ë¤³¤È¤ÇưŪ¤ËÊѹ¹¤¹¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£


¥²¡¼¥à¼Â¹ÔÁ°



¥²¡¼¥à¼Â¹Ô»þ



¡¡¤¤¤º¤ì¤ÎÀ©¸æ½èÍý¤â¡¢AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤òÊÑ¿ô¤ËÂåÆþ¤¹¤ë¤³¤È¤ÇÌ¿Îá¤ò½Ð¤¹¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

        // BGMÄä»ß
        audioSource.Stop();

        // ºÆÀ¸¤¹¤ëBGM¤òÀßÄꤹ¤ë
        audioSource.clip = bgms[(int)bgmType];

        // BGMºÆÀ¸
        audioSource.Play();

»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
AudioSource
https://docs.unity3d.com/ja/current/ScriptReferenc...
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
AudioSource.Play
https://docs.unity3d.com/ja/current/ScriptReferenc...
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
AudioSource.Stop
https://docs.unity3d.com/ja/current/ScriptReferenc...
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
AudioSource.clip
https://docs.unity3d.com/ja/2019.4/ScriptReference...


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


¡¡¥Ò¥¨¥é¥ë¥­¡¼¤Î¶õ¤¤¤Æ¤¤¤ë¾ì½ê¤òÁªÂò¤·¤Æ±¦¥¯¥ê¥Ã¥¯¤ò¤·¤Æ¥á¥Ë¥å¡¼¤ò³«¤­¡¢Create Empty ¤òÁªÂò¤·¤Æ¶õ¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò£±¤ÄºîÀ®¤·¤Þ¤¹¡£
̾Á°¤ò AudioManager ¤ËÊѹ¹¤·¤Þ¤¹¡£


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



AudioManager ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü
¡¡


¡¡Àè¤Û¤ÉºîÀ®¤·¤¿ AudioManager ¥¹¥¯¥ê¥×¥È¤ò¥É¥é¥Ã¥°¥¢¥ó¥É¥É¥í¥Ã¥×¤·¤Æ¥¢¥¿¥Ã¥Á¤·¤Æ¤¯¤À¤µ¤¤¡£


AudioManager ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¹¥¯¥ê¥×¥È¤ò¥¢¥¿¥Ã¥Á¸å¤Î¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü




¡¡¥¢¥¿¥Ã¥Á¤µ¤ì¤¿ AudioManager ¥¹¥¯¥ê¥×¥È¤ÎÀßÄê¤ò¹Ô¤¤¤Þ¤¹¡£bgms ÊÑ¿ô¤ÏÇÛÎó¤Ç¤¹¤Î¤Ç¡¢¤½¤ÎŤµ(ÇÛÎó¤ÎÍ×ÁÇ¿ô)¤òÀßÄꤹ¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
¤³¤ì¤Ï Size ¤ÎÃͤòÊѹ¹¤¹¤ë¤³¤È¤Ç»ØÄê¤Ç¤­¤Þ¤¹¡£º£²óÍÑ°Õ¤·¤¿¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤Ï£²¼ïÎà¤Ç¤¹¤Î¤Ç¡¢Size ¤ò 0 ¤«¤é 2 ¤ËÊѹ¹¤·¤Æ¤¯¤À¤µ¤¤¡£


Size ¤òÀßÄê



¡¡Size ¤ò 1 °Ê¾å¤ËÊѹ¹¤¹¤ë¤È¡¢ÇÛÎó¤ÎÍ×ÁǤòÀßÄê¤Ç¤­¤ë Element ¤¬Äɲ䵤ì¤Þ¤¹¡£¤³¤ì¤ÏÇÛÎó¤ÎÍ×ÁÇÈÖ¹æ¤òɽ¤·¤Æ¤ª¤ê¡¢0 ¤«¤é»Ï¤Þ¤ê¤Þ¤¹¡£
Element 0 ¤Ï bgms[0]¡¢Element 1 ¤Ï bgms[1] ¤ò»ØÄꤹ¤ë¤³¤È¤Ç¡¢¤½¤ÎÃæ¿È¤ò»²¾È¤Ç¤­¤Þ¤¹¡£

¡¡¤³¤ÎÇÛÎó¤Ï AudioClip ·¿¤Ç¤¹¤Î¤Ç¡¢Unity ¤Ë¥¤¥ó¥Ý¡¼¥È¤·¤¿¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤òÀßÄꤹ¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
¥É¥é¥Ã¥°¥¢¥ó¥É¥É¥í¥Ã¥×¤·¤Æ¡¢Element 0 ¤Ë¤Ï Main ÍѤΥª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¡¢Element 1 ¤Ë¤Ï GameClear ÍѤΥª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤ò¥¢¥µ¥¤¥ó¤·¤Æ¤¯¤À¤µ¤¤¡£


¡ã¼ê½çÆ°²è¡¡¥¢¥µ¥¤¥ó¡ä
https://gyazo.com/e933be6e252d19605724ce1456bd1230


AudioManager ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¢¥µ¥¤¥ó¸å¤Î¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü




¡¡ºÇ¸å¤Ë¡¢AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤òÄɲä·¤Þ¤¹¡£
AudioManager ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÁªÂò¤·¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤Î°ìÈÖ²¼¤Ë¤¢¤ë Add Component ¥Ü¥¿¥ó¤ò²¡¤·¤Æ¡¢AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤òÄɲä·¤Þ¤¹¡£

¡¡AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ÎÀßÄê¤ò¹Ô¤¤¤Þ¤¹¡£

¡¡Volume ¤ò 0.1 ¤ËÊѹ¹¤·¤Æ¤¯¤À¤µ¤¤¡£¾®¤µ¤¤²»Î̤«¤éÂ礭¤¯Ä´À°¤·¤Þ¤¹¡£

¡¡Play on Awake ¤Î¥Á¥§¥Ã¥¯¤ò³°¤·¤Æ¤¯¤À¤µ¤¤¡£

¡¡AudioClip ¤Ï None ¤Î¤Þ¤Þ¤ÇÌäÂꤢ¤ê¤Þ¤»¤ó¡£
¤³¤ÎÉôʬ¤ò¥¹¥¯¥ê¥×¥È¤«¤éÁàºî¤·¤ÆBGM¤ËÍøÍѤ¹¤ë¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤òbgms[0]¡¢¤¢¤ë¤¤¤Ï bgms[1] ¤ËÀßÄꤷ¤¿¥ª¡¼¥Ç¥£¥ª¥Õ¥¡¥¤¥ë¤Ë
¥²¡¼¥àÃæ¤ËÀÚ¤êÂؤ¨¤Þ¤¹¡£


AudioManager ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü



¡¡AudioManager ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë´Ø¤·¤Æ¤ÎÀßÄê¤Ï´°Î»¤Ç¤¹¡£


£¶¡¥GameManager ¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤Æ¡¢AudioManager ¥¹¥¯¥ê¥×¥È¤Î PlayBGM ¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤·¤ÆBGM¤òÊѹ¹¤¹¤ë


¡¡AudioManager ¥¹¥¯¥ê¥×¥È¤ËÍÑ°Õ¤·¤¿ PlayBGM ¥á¥½¥Ã¥É¤ò GameManager ¥¹¥¯¥ê¥×¥È¤«¤é¸Æ¤Ó½Ð¤¹¤è¤¦¤Ë½èÍý¤òÄɲä·¤Þ¤¹¡£
AudioManager ¥¹¥¯¥ê¥×¥È¤ò¼èÆÀ¤·¡¢¤É¤ÎÉôʬ¤Ë PlayBGM ¥á¥½¥Ã¥É¤òÄɲ乤ì¤Ð¤è¤¤¤«¤ò¹Í¤¨¤Æ¼ÂÁõ¤ò¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£

¡¡¤Ê¤ª¡¢PlayBGM ¥á¥½¥Ã¥É¤Î°ú¿ô¤Ï BgmType ·¿¤Ç¤¹¡£
AudioManager ¥¹¥¯¥ê¥×¥ÈÆâ¤ÇÀë¸À¤µ¤ì¤Æ¤¤¤ë enum ¤Ç¤¹¤Î¤Ç¡¢»ØÄꤹ¤ë¾ì¹ç¤Ë¤Ï¡¢AudioManager.BgmType ¤Èµ­½Ò¤·¤Æ¤«¤éÎóµó»Ò¤ò»ØÄꤹ¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£


GameManager.cs(¼«Ê¬¤ÇºîÀ®¤·¤Æ¤¤¤ë¥¹¥¯¥ê¥×¥È¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢¤½¤Î¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤¹¤ë)

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



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


¡¡PlayBGM ¥á¥½¥Ã¥ÉÆâ¤Ë Debug.Log ¥á¥½¥Ã¥É¤òÍÑ°Õ¤·¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢BGM¤¬ÀÚ¤êÂؤï¤ë¥¿¥¤¥ß¥ó¥°¤Ç Console ¥Ó¥å¡¼¤Ë BgmType ¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£
¥²¡¼¥à¤Î¼Â¹Ô»þ¤Ë Main¡¢Ãå¿å»þ¤Ë GameClear ¤Èɽ¼¨¤µ¤ì¤ì¤ÐÀ©¸æÀ®¸ù¤Ç¤¹¡£
¤³¤Á¤é¤òÍøÍѤ·¤Ä¤Ä¡¢BGM¤¬»ØÄꤵ¤ì¤¿¥¿¥¤¥ß¥ó¥°¤ÇÀÚ¤êÂؤï¤ë¤è¤¦¤ËÀ©¸æ¤Ç¤­¤Æ¤¤¤ë¤«¤ò³Îǧ¤·¤Þ¤¹¡£





¡¡¥Ü¥ê¥å¡¼¥à¤ò 0.1 ¤Ë¹Ê¤Ã¤Æ¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢¤â¤·¤â¾®¤µ¤¤¤è¤¦¤Ç¤¢¤ì¤Ð¿ôÃͤòÂ礭¤¯¤·¤Þ¤¹¡£
¤¿¤À¤·¥Ü¥ê¥å¡¼¥à¤ò²á¤®¤ë¤È¡¢SE¤Î²»¤¬Ê¹¤³¤¨¤Ê¤¯¤Ê¤ë¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢¤½¤ÎÊÕ¤ê¤ò³Îǧ¤·¤Ê¤¬¤éÄ´À°¤ò¹Ô¤Ã¤Æ¤¯¤À¤µ¤¤¡£


¡ã¼Â¹ÔÆ°²è¡¡Console ¤ËÀÚ¤êÂؤï¤ëBGM¤¬É½¼¨¤µ¤ì¤ë¡ä
https://gyazo.com/eaf44702317b2a3417d1d9c15a7f1b12


¡ã¼Â¹ÔÆ°²è¡¡AudioClip ¤ÎÃͤ¬¥²¡¼¥à¤Î¾ìÌ̤˱þ¤¸¤Æ None => Main => GameClear ¤ÈÀÚ¤êÂؤï¤Ã¤ÆºÆÀ¸¤µ¤ì¤ëBGM¤¬ÊѤï¤ë¡ä
https://gyazo.com/f2538d37e0c0509a5ef3efb4516b5dba


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

¡¡=>¡¡¼¡¤Ï¡¡¼ê½ç£²£·¡¡¡¼¥´¡¼¥ëÃÏÅÀ¤Ë²ÖÎؤòÍÑ°Õ¤¹¤ë¡¼¡¡¤Ç¤¹¡£

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


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

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

Menu


´ðÁÃ

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

private



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

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