ºÇ½ª¹¹¿·¡§
orika_ex_miyako 2024ǯ07·î30Æü(²Ð) 19:10:05ÍúÎò
@nmxiÍÍ
º£Æü¤«¤é¤Ï¤¸¤á¤ëUnity
https://qiita.com/nmxi/items/7950fb12ef925efa276d
https://github.com/nmxi/UnityBreakOut
¡¡¥·¡¼¥ó¤Î³«»Ï¤ÈƱ»þ¤ËBGM¤òÌĤ餹ÊýË¡¤Ç¤¹¡£¤¤¤¯¤Ä¤«ÊýË¡¤¬¤¢¤ê¤Þ¤¹¤¬¡¢¤³¤³¤Ç¤Ï°ìÈÖ´Êñ¤ÊÊýË¡¤ò¤´¾Ò²ð¤·¤Þ¤¹¡£
¡¡¤Þ¤º¤ÏÀ߷פȼÂÁõ¼ê½ç¤Ë¤Ä¤¤¤Æ¤Þ¤È¤á¤Æ¤ª¤¤Þ¤¹¡£
£±¡¥ºÆÀ¸¤·¤¿¤¤BGM¤ò´ÉÍý¤¹¤ë¤¿¤á¤Î¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤·¤Þ¤¹ £²¡¥¥¢¥»¥Ã¥È¥¹¥È¥¢¤¢¤ë¤¤¤Ï¸¡º÷¥¨¥ó¥¸¥ó¤òÍøÍѤ·¤Æ¡¢ÌµÎÁ¤Î²»³ÚÁǺà¤òÆþ¼ê¤·¤Þ¤¹ £³¡¥¥¤¥ó¥Ý¡¼¥È¤¹¤ë²»¸»¥Õ¥¡¥¤¥ë¤ò£±¤Ä¤Î¥Õ¥©¥ë¥À¤Ë¤Þ¤È¤á¤é¤ì¤ë¤è¤¦¤ËBGM¥Õ¥©¥ë¥À¤òºîÀ®¤·¤Þ¤¹ £´¡¥²»¸»¥Õ¥¡¥¤¥ë¤òUnity¤Ë¥¤¥ó¥Ý¡¼¥È¡ÊÄɲáˤ·¤Þ¤¹ £µ¡¥²»¸»¥Õ¥¡¥¤¥ë¤òUnity¤ÇºÆÀ¸¤¹¤ë¤è¤¦¤ËAudioSource¥³¥ó¥Ý¡¼¥Í¥ó¥È¤òÄɲä·¤Þ¤¹ £¶¡¥AudioSourceÆâ¤ÎAudioClip¤Î¡ÖNone¡×¤Î¾ì½ê¤Ë¡¢ÌĤ餷¤¿¤¤²»¸»¥Õ¥¡¥¤¥ë¤ò¥¢¥µ¥¤¥ó¡Ê»ØÄê¡Ë¤·¤Þ¤¹ £·¡¥¥¨¥Ç¥£¥¿¡¼¤Ë¤Æ¥²¡¼¥à¤ò¼Â¹Ô¤¹¤ë¤È¡¢BGM¤¬ºÆÀ¸¤µ¤ì¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¡ÖBGM ¥²¡¼¥à ̵ÎÁ¡×¤Ê¤É¤òÂǤĤȸ¡º÷¤¬²Äǽ¤Ç¤¹¡£
¡¡¥À¥¦¥ó¥í¡¼¥É¤·¤ÆPC¤ËÊݸ¤·¤Æ¤¯¤À¤µ¤¤¡£²»¸»¥Õ¥¡¥¤¥ë¤Ï¥µ¥¤¥º¤Î¾®¤µ¤¤¡¢mp3¥Õ¥¡¥¤¥ë¤¬¤ª¤¹¤¹¤á¤Ç¤¹¡£
¡¡Àè¤Û¤É¥Ò¥¨¥é¥ë¥¡¼¤ËºîÀ®¤·¤¿¡ÖAudio¡ÊBGM¡Ë¡×¥ª¥Ö¥¸¥§¥¯¥È¤òÁªÂò¤·¤Æ¡¢±¦Â¦¤Î¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤ò³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£
¸½ºß¤ÏTransform¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¤ß¥¢¥¿¥Ã¥Á¤µ¤ì¤Æ¤¤¤ë¾õÂ֤Ǥ¹¤Î¤Ç¡¢¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤ÎºÇ²¼Ãʤè¤ê¡ÖAdd Component¡×¤òÁªÂò¤·¤Þ¤¹¡£
¡¡
¡¡Audio -> AudioSource¡¡¤òÁªÂò¤¹¤ë¤ÈAudio¡ÊBGM¡Ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤¬Äɲ䵤ì¤Þ¤¹¡£
![](https://image02.seesaawiki.jp/i/o/i-school-memo/PNksCwqV7Q-s.png)
¡¡ÀèÄøºîÀ®¤·¤¿BGM¥Õ¥©¥ë¥À¤è¤ê¡¢¥²¡¼¥àÆâ¤ÇºÆÀ¸¤·¤¿¤¤²»¸»¥Õ¥¡¥¤¥ë¤ò£±¤ÄÁª¤ó¤Ç¡¢
Audio¡ÊBGM¡Ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ÎAudioClip Íó¤Ë¥É¥é¥Ã¥°¡õ¥É¥í¥Ã¥×¤·¤Æ¥¢¥µ¥¤¥ó¤·¤Þ¤¹¡£(²¼µ¤ÎÆ°²è¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤)
¡¡AudioSource ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î Loop¡Ê²»¸»¤ÎºÆÀ¸¤¬½ªÎ»¤·¤¿¾ì¹ç¡¢ºÇ½é¤«¤é¤â¤¦°ìÅ٥롼¥×ºÆÀ¸¤µ¤»¤ë¡Ë¤È PlayOnAwake¡Ê¥²¡¼¥à³«»Ï¤ÈƱ»þ¤ËºÆÀ¸¡Ë¤Ë¤Ï¡¢¥Á¥§¥Ã¥¯¤òÆþ¤ì¤¿¤Þ¤Þ¤ÇÂç¾æÉפǤ¹¡£
https://gyazo.com/5b52ba29b9635d4c4513d087de22865c
¡¡Result¥·¡¼¥ó¤Ë¤Ï¥²¡¼¥à¤Î¾õÂ֤˱þ¤¸¤Æ¡¢¥¯¥ê¥¢¤·¤Æ¤¤¤ë¾ì¹ç¤È¡¢¥²¡¼¥à¥ª¡¼¥Ð¡¼¤Ë¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¤Î2¼ïÎà¤Î¾õÂÖ¤¬¤¢¤ê¤Þ¤¹¡£
¸½ºß¤ÎÊýË¡¤Ç¤Ï¤É¤Á¤é¤Î¾õÂÖ¤ÇResult¥·¡¼¥ó¤ËÁ«°Ü¤·¤Æ¤âƱ¤¸BGM¤¬ÌĤ뤿¤á¡¢±þÍѤȤ·¤Æ¡¢¤³¤Î¥²¡¼¥à¤Î¾õÂ֤˱þ¤¸¤Æ¡¢BGM¤òÊѲ½¤µ¤»¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
¡¡À߷פȤ·¤Þ¤·¤Æ¤Ï¡¢AudioSource¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ÎAudioClip¥×¥í¥Ñ¥Æ¥£¤Î¾ðÊó¤ò¡¢¥²¡¼¥à¤Î¾õÂ֤˹ç¤ï¤»¤Æ¥¹¥¯¥ê¥×¥È¤«¤éÊѹ¹¤·¤Þ¤¹¡£
AudioSource¥³¥ó¥Ý¡¼¥Í¥ó¥È¤¬CD¥×¥ì¥¤¥ä¡¼¤ÎÌò³ä¤Ç¡¢AudioClipÍó¤ÏºÆÀ¸¤·¤¿¤¤CD¤¬Æþ¤ë¾ì½ê¡¢¤À¤È¹Í¤¨¤Æĺ¤¯¤È¥¤¥á¡¼¥¸¤¬¤ï¤¤ä¤¹¤¤¤È»×¤¤¤Þ¤¹¡£
¡¡¤³¤Î±þÍѤǤϡ֥¹¥¯¥ê¥×¥È¤Î½èÍý¤Ë¤è¤Ã¤Æ¥²¡¼¥àÆâ¤ÇưŪ¤ËºÆÀ¸¤¹¤ë²»¸»¥Õ¥¡¥¤¥ë¤òÊѹ¹¤¹¤ë¡×½èÍý¤Ë¤Ä¤¤¤Æ³Ø½¬¤·¡¢
¥²¡¼¥à¥¯¥ê¥¢»þ¤ÎBGM¤È¡¢¥²¡¼¥à¥ª¡¼¥Ð¡¼»þ¤ÎBGM¤È¤Ç¡¢ÊÌ¡¹¤ÎBGM¤òÌĤ餹¤è¤¦¤Ë¤·¤Þ¤·¤ç¤¦¡£
¡¡À߷פȼÂÁõ¼ê½ç¤Ë¤Ä¤¤¤Æ¤Þ¤È¤á¤Æ¤ª¤¤Þ¤¹¡£
£±¡¥ºÇ½é¤Î¡ÖBGM¤òÌĤ餹¡×¤Î¼ê½ç£±¡Á£µ¤Þ¤Ç¤ò¹Ô¤Ã¤Æ¡¢Result¥·¡¼¥ó¤ËAudio¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤·¡¢AudioSource¥³¥ó¥Ý¡¼¥Í¥ó¥È¤òÄɲ乤ë½ê¤Þ¤ÇƱ¤¸¾õÂ֤ǿʤá¤Þ¤¹ £²¡¥DataSender¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤ÆMain¥·¡¼¥ó½ªÎ»»þ¤Ë¥²¡¼¥à¤Î¾õÂÖ¤òÊÝ»ý¤Ç¤¤ë¤è¤¦¤Ë¤·¤Þ¤¹ £³¡¥TextDataFetcher¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¡¢¥²¡¼¥à¤Î¾õÂ֤˱þ¤¸¤Æ²»¸»¤òÊѹ¹¤·¤ÆºÆÀ¸¤Ç¤¤ë¤è¤¦¤Ë¤·¤Þ¤¹ £´¡¥GameMaster¥¹¥¯¥ê¥×¥È¤ÈKabeOut¥¹¥¯¥ê¥×¥È¤Ë¤¢¤ëGameOver´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹½èÍý¤ò¤½¤ì¤¾¤ì½¤Àµ¤·¤Æ¡¢isGameClearÊÑ¿ô¤ËÃͤòÂåÆþ¤¹¤ë½èÍý¤òÄɲä·¤Þ¤¹ £µ¡¥¥²¡¼¥à¤ò¼Â¹Ô¤·¤Æ¥²¡¼¥à¥¯¥ê¥¢»þ¤È¥²¡¼¥à¥ª¡¼¥Ð¡¼»þ¤ÎBGM¤¬ÊѲ½¤¹¤ë¤«³Îǧ¤·¤Þ¤¹
using System.Collections; using System.Collections.Generic; using UnityEngine; public static class DataSender¡¡ { public static string resultMessage; public static bool isGameClear; // <= Äɲà }
¡¡bool·¿¤ÎisGameClearÊÑ¿ô¤ò¿·¤·¤¯static¤Î¾ðÊó¤È¤·¤ÆÄɲä·¤Þ¤·¤¿¡£¤³¤ÎÊÑ¿ô¤¬¥²¡¼¥à¤Î¾õÂÖ¤òɽ¸½¤·¤Þ¤¹¡£
¤³¤ÎÊÑ¿ô¤ò»È¤Ã¤ÆMain¥·¡¼¥ó¤ò½ªÎ»¤¹¤ë¥¿¥¤¥ß¥ó¥°¡ÊGameOver´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹½èÍý¡Ë¤Ç true / false ¤òÀÚ¤êÂؤ¨¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
isGameClear == true ¤Ç¤¢¤ì¤Ð¡Ö¥²¡¼¥à¥¯¥ê¥¢¤Î¾õÂÖ¡×
isGameClear == false ¤Ç¤¢¤ì¤Ð¡Ö¥²¡¼¥à¥ª¡¼¥Ð¡¼¤Î¾õÂÖ¡×
¤È¤¹¤ë¤³¤È¤Ç¡¢¤³¤Î¾ðÊó¤ò»È¤¤¡¢À©¸æʸ¤ò»È¤Ã¤ÆMain¥·¡¼¥ó¤Î·ë²Ì¤Ë¤è¤Ã¤ÆResult¥·¡¼¥ó¤ÎºÆÀ¸¤¹¤ë²»¸»¤òʬ´ô¤µ¤»¤ë¤³¤È¤¬²Äǽ¤Ë¤Ê¤ê¤Þ¤¹¡£
¿·¤·¤¯ÊÑ¿ô¤ò£²¤ÄÀë¸À¤·¤Þ¤¹¡£¤Þ¤¿¡¢Start¥á¥½¥Ã¥ÉÆâ¤Ëʬ´ô½èÍý¤òÄɲ䷤ơ¢¥²¡¼¥à¤Î¾õÂ֤˱þ¤¸¤Æ²»¸»¤òÊѹ¹¤·¤ÆºÆÀ¸¤Ç¤¤ë¤è¤¦¤Ë¤·¤Þ¤¹
TextDataFetcher.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //¤³¤ì¤¬¤¢¤ë¤³¤È¤Ç¡¢UnityEngine.UI.Text¤È½ñ¤«¤Ê¤¯¤Æ¤â¤è¤¯¤Ê¤ë public class TextDataFetcher : MonoBehaviour { // Text¥¯¥é¥¹·¿¤Î»²¾È·¿ÊÑ¿ôresultMessageText¤Ë¤Ï¡¢¤³¤Î¥¹¥¯¥ê¥×¥È¤¬Å¬ÍѤµ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È(=Master¥ª¥Ö¥¸¥§¥¯¥È)¤ÎInspecter¥¿¥Ö¤ÎResultMessageText¤Ë»ØÄꤷ¤¿¥ª¥Ö¥¸¥§¥¯¥È(¡á·ë²Ì¤òÆþ¤ì¤ëÊý¤ÎText¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È)¤ÎIDÈֹ椬³ÊǼ¤µ¤ì¤ë¡£ public Text resultMessageText; // AudioClip¥¯¥é¥¹·¿¤ÎÇÛÎóaudioClips¤ÎÍ×ÁǤˤϡ¢¤³¤Î¥¹¥¯¥ê¥×¥È¤òŬÍѤ·¤¿Master¥ª¥Ö¥¸¥§¥¯¥È¤ÎInspector¥¿¥Ö¤ÎAudio Clips¤ÎElement0¡¢Element1¤Ë»ØÄꤷ¤¿²»³Ú¤ÎIDÈֹ椬³ÊǼ¤µ¤ì¤ë public AudioClip[] audioClips; // <=¡¡¡ù¡¡Äɲà // AudioSource¥¯¥é¥¹·¿¤Î»²¾È·¿ÊÑ¿ôaudioSource¤Ë¤Ï¡¢¤³¤Î¥¹¥¯¥ê¥×¥È¤òŬÍѤ·¤¿Master¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ÎInspector¥¿¥Ö¤ÎAudio Source¤Ë»ØÄꤷ¤¿Audio¥ª¥Ö¥¸¥§¥¯¥È¤ÎIDÈֹ椬³ÊǼ¤µ¤ì¤ë public AudioSource audioSource; // <=¡¡¡ù¡¡Äɲà void Start() { // resultMessageText¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ëIDÈֹ椬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥È(¡á·ë²Ì¤òÆþ¤ì¤ëÊý¤ÎText¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È)¤Î»²¾È·¿ÊÑ¿ôtext¤Ë // DataSender¥¯¥é¥¹¤Î»²¾È·¿ÊÑ¿ôresultmessage¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ëIDÈֹ椬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥È(¡á¿·¤·¤¤Ê¸»úÎ󤬵ºÜ¤µ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È)¤ÎIDÈÖ¹æ¤òÂåÆþ¤¹¤ë¡£ // ¤³¤ì¤Ë¤è¤Ã¤Æ¡¢·ë²Ì¤òÆþ¤ì¤ëÊý¤ÎText¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Îʸ»úÎ󤬿·¤·¤¤Ê¸»úÎó¤ËÆþ¤ìÂؤï¤ë¡£ resultMessageText.text = DataSender.resultMessage; ///* °Ê²¼¤Î½èÍý¤òÄɲä·¤Þ¤¹ */// ¡¡¡¡¡¡¡¡// ²»¸»¤ÎÊѹ¹Ê¬´ô½èÍý¡£¤³¤³¤Ç¥²¡¼¥à¤Î¾õÂ֤˱þ¤¸¤ÆºÆÀ¸¤¹¤ë²»¸»¥Õ¥¡¥¤¥ë¤ò·èÄꤷ¤ÆAudioSource¤ÎAudioClip¤Ë¥»¥Ã¥È¤¹¤ë // ¤â¤·DataSender¥¯¥é¥¹¤ÎÊÑ¿ôisGameClear¤¬true¤Ê¤é¡¢¥²¡¼¥à¥¯¥ê¥¢¤Î¾õÂ֤Ȥ¹¤ë if (DataSender.isGameClear) { // (ÇÛÎóaudioClips¤ÎÀèƬ¥¢¥É¥ì¥¹+0ÈÖÌܤΥ¢¥É¥ì¥¹¤ÎÃæ¿È¤Ç¤¢¤ë)Element0¤ÎIDÈÖ¹æ¤ò»²¾È·¿ÊÑ¿ôclip¤Ë³ÊǼ¤¹¤ë audioSource.clip = audioClips[0]; } // ¤â¤·DataSender¥¯¥é¥¹¤ÎÊÑ¿ôisGameClear¤¬false¤Ê¤é¡¢¥²¡¼¥à¥ª¡¼¥Ð¡¼¤Î¾õÂ֤Ȥ¹¤ë else { // (ÇÛÎóaudioClips¤ÎÀèƬ¥¢¥É¥ì¥¹+1ÈÖÌܤΥ¢¥É¥ì¥¹¤ÎÃæ¿È¤Ç¤¢¤ë)Element1¤ÎIDÈÖ¹æ¤ò»²¾È·¿ÊÑ¿ôclip¤Ë³ÊǼ¤¹¤ë audioSource.clip = audioClips[1]; } // »²¾È·¿ÊÑ¿ôclip¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ëIDÈֹ椬»Ø¤·¼¨¤¹²»³Ú¤òºÆÀ¸¤¹¤ë audioSource.Play(); } ///* ¤³¤³¤Þ¤Ç */// }
¡¡Start¥á¥½¥Ã¥ÉÆâ¤ËisGameClear¤Î¾õÂÖ¤ò³Îǧ¤¹¤ëʬ´ô½èÍý¤òºî¤Ã¤Æ¡¢¥²¡¼¥à¤Î¾õÂ֤˱þ¤¸¤ÆºÆÀ¸¤¹¤ë²»¸»¤òÀßÄꤹ¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
¤³¤Î½èÍý¤Ë¤è¤Ã¤Æ¥²¡¼¥à¥¯¥ê¥¢»þ¤È¥²¡¼¥à¥ª¡¼¥Ð¡¼»þ¤Î²»³Ú¤¬ÊѲ½¤¹¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¥¹¥¯¥ê¥×¥È¤Î½¤Àµ¤¬½ª¤ï¤Ã¤¿¤é¡¢Master¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤ò³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£public½¤¾þ»Ò¤ÇÀë¸À¤·¤¿ÊÑ¿ô¤¬£²¤ÄÄɲ䵤ì¤Æ¤¤¤Þ¤¹¡£
![](https://image01.seesaawiki.jp/i/o/i-school-memo/J9zK3F7XK3-s.png)
¡¡AudioClips¤Ë¤Ï¡¢Result¥·¡¼¥ó¤ÇºÆÀ¸¤¹¤ë²»¸»¥Õ¥¡¥¤¥ë¤ò»ØÄꤷ¤Þ¤¹¡£¤³¤Á¤é¤ÏÇÛÎó¤Ç¤¹¤Î¤Ç¡¢Size¤ò2¤ËÊѹ¹¤¹¤ë¤ÈElement¾ðÊó0 -1¤¬Äɲ䵤ì¤Þ¤¹¤Î¤Ç
¤É¤Á¤é¤âBGM¥Õ¥©¥ë¥À¤«¤é¡¢Element0¤Ë¤Ï¥²¡¼¥à¥¯¥ê¥¢»þ¤Î²»¸»¥Õ¥¡¥¤¥ë¤ò¥¢¥µ¥¤¥ó¤·¤Þ¤¹¡£Element1¤Ë¤Ï¥²¡¼¥à¥ª¡¼¥Ð¡¼»þ¤Î²»¸»¥Õ¥¡¥¤¥ë¤ò¥¢¥µ¥¤¥ó¤·¤Þ¤¹¡£
![](https://image01.seesaawiki.jp/i/o/i-school-memo/SKTNCoNdfJ-s.png)
¡¡AudioSource¤Ë¤Ï¡¢¥Ò¥¨¥é¥ë¥¡¼¤Ë¤¢¤ëAudio¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î»ý¤ÄAudioSource¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ò¥¢¥µ¥¤¥ó¤·¤Þ¤¹¡£
¥Ò¥¨¥é¥ë¥¡¼¤Ë¤¢¤ëAudio¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¥É¥é¥Ã¥°¥¢¥ó¥É¥É¥í¥Ã¥×¤·¤Æ¡¢¤³¤Á¤é¤Ë¥¢¥µ¥¤¥ó¤·¤Þ¤¹¡£
¥¢¥µ¥¤¥óÆ°²è
https://gyazo.com/13d1ea68f5141c9fee7575fac29834f8¡¡
´°À®¾õÂ֤Υ¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü
![](https://image01.seesaawiki.jp/i/o/i-school-memo/3tRIbhXKP5-s.png)
£´¡¥GameMaster¥¹¥¯¥ê¥×¥È¤ÈKabeOut¥¹¥¯¥ê¥×¥È¤Ë¤¢¤ëGameOver´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹½èÍý¤ò¤½¤ì¤¾¤ì½¤Àµ¤·¤Æ¡¢isGameClearÊÑ¿ô¤ËÃͤòÂåÆþ¤¹¤ë½èÍý¤òÄɲä·¤Þ¤¹ ![](https://static.seesaawiki.jp/img/usr_second/common/icon_pen.gif)
GameMaster.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; //SceneManager.LoadScene("Result");¤òÆ°¤«¤¹¤¿¤á¤ËɬÍ× public class GameMaster : MonoBehaviour { ¡¡¡¡(¾Êά) void Update() { // nowTime¤Ëº£¤Þ¤Ç¤Ë·Ð²á¤·¤¿»þ´Ö¤òÆþ¤ì¤Æ¤¤¤Þ¤¹¡¥Time.deltaTime¤Ç¤ÏÁ°¤Î¥Õ¥ì¡¼¥à¤«¤é·Ð²á¤·¤¿»þ´Ö¤ò¼èÆÀ¤Ç¤¤Þ¤¹¡¥ // Update()¤ÏËè¥Õ¥ì¡¼¥à¼Â¹Ô¤µ¤ì¤ë¤Î¤Ç¤½¤Î·Ð²á»þ´Ö¤òËè¥Õ¥ì¡¼¥à¤¹¤³¤È¤Ç·Ð²á»þ´Ö¤ò¼èÆÀ¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹ nowTime += Time.deltaTime; // ¤â¤·º£¤Î¥Ü¥Ã¥¯¥¹¿ô¤¬0°Ê²¼¤Ê¤éGameOver´Ø¿ô¤ò¸Æ¤Ó½Ð¤·¡¢Result¥·¡¼¥ó¤Ë°ÜÆ°¤¹¤ë¡£ if (boxNum <= 0) { // nowTime.ToString("F0")¡ánowTime¤ò¾®¿ôÅÀÂè0°Ì¤Þ¤Ç(¡á¾®¿ôÅÀ°Ê²¼¤Ê¤·)¤Îʸ»úÎó¤ËÊÑ´¹¤¹¤ë GameOver(nowTime.ToString("F0")+"Éäǥ¯¥ê¥¢¤Ç¤¤¿!", true); // <= ¡ù¡¡Âè2°ú¿ô¤È¤·¤Æ true ¤òÄɲä·¡¢¥²¡¼¥à¥¯¥ê¥¢¤Î¾õÂÖ¤òÅϤ¹ } } /// <summary> /// ¥²¡¼¥à½ªÎ»»þ¤Ë¤è¤Ð¤ì¤ë½èÍý /// ¥²¡¼¥à½ªÎ»¤È¤Ï¡¢¥²¡¼¥à¥¯¥ê¥¢»þ¤È¥²¡¼¥à¥ª¡¼¥Ð¡¼»þ¤Î2¼ïÎब¤¢¤ë /// </summary> /// <param name="resultMessage">¥²¡¼¥à¤Î¾õÂ֤˹ç¤ï¤»¤¿¥á¥Ã¥»¡¼¥¸¤¬ÂåÆþ¤µ¤ì¤Æ¤¤¤ë</param> /// <param name="isGameClear">Main¥·¡¼¥ó½ªÎ»»þ¤Î¥²¡¼¥à¤Î¾õÂÖ¤¬ÂåÆþ¤µ¤ì¤Æ¤¤¤ë¡£true = ¥²¡¼¥à¥¯¥ê¥¢¡¢false = ¥²¡¼¥à¥ª¡¼¥Ð¡¼</param> public void GameOver(string resultMessage, bool isClear) // <= ¡ù¡¡Âè2°ú¿ô¤òÄɲᣥ²¡¼¥à¤Î¾õÂÖ¤ò¼õ¤±¼è¤ë¤è¤¦¤Ë¤¹¤ë { DataSender.resultMessage = resultMessage; // ¥²¡¼¥à¤Î¾õÂÖ(¥²¡¼¥à¥¯¥ê¥¢¤Ê¤étrue¡¢¥²¡¼¥à¥ª¡¼¥Ð¡¼¤Ê¤éfalse¤È¤·¤ÆÃͤ¬°ú¿ô¤ËÆϤ¤¤Æ¤¤¤ë)¤òÂåÆþ DataSender.isGameClear = isClear; // <= ¡ù¡¡Äɲá£Âè2°ú¿ô¤Î¾ðÊó¤òstatic¤ÎÊÑ¿ô¤ËÂåÆþ¤¹¤ë¡£¤³¤Î¾ðÊó¤Ï¥·¡¼¥óÁ«°Ü¤·¤Æ¤â¼º¤ï¤ì¤Ê¤¤ // Result¤È¤¤¤¦Ì¾Á°¤Î¡É¥·¡¼¥ó¡É¤Ë°ÜÆ°¤·¤í¡¥¤È¤¤¤¦Ì¿Îá SceneManager.LoadScene("Result"); } }
KabeOut.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; public class KabeOut : MonoBehaviour { // ¤³¤Î¥¹¥¯¥ê¥×¥È¤¬Å¬ÍѤµ¤ì¤Æ¤¤¤ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë¥ª¥Ö¥¸¥§¥¯¥È¤¬¤¢¤¿¤Ã¤Æ¤¤¿¤È¤¡¢¤³¤Î´Ø¿ô¤Ï¸Æ¤Ð¤ì¤ë¡£ // ¤¢¤¿¤Ã¤Æ¤¤¿¥ª¥Ö¥¸¥§¥¯¥È¤ÎIDÈֹ椬°ú¿ô¤È¤·¤Æ¡¢»²¾È·¿ÊÑ¿ôcollision¤ËÂåÆþ¤µ¤ì¤ë¡£ private void OnCollisionEnter(Collision collision) { //Master¥ª¥Ö¥¸¥§¥¯¥È¤Î»ý¤ÄGameMaster¥³¥ó¥Ý¡¼¥Í¥ó¥È(¥¹¥¯¥ê¥×¥È)¤ÎGameOver´Ø¿ô¤ò¸Æ¤Ö GameObject.Find("Master").GetComponent<GameMaster>().GameOver("¥²¡¼¥à¼ºÇÔ. ¤Þ¤¿Ä©À路¤è¤¦", false); // ¡ù¡¡<= Âè2°ú¿ô¤òÄɲ乤ë } }
¡¡³Æ¥¹¥¯¥ê¥×¥È¤Ë¤¢¤ëGameOver´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹½èÍý¤Ë¡¢Âè2°ú¿ô(bool·¿¤Î¾ðÊó)¤òÄɲä·¤Þ¤¹¡£¤³¤ÎÃͤòisGameOverÊÑ¿ô¤ËÂåÆþ¤¹¤ë¤³¤È¤Ç¡¢Result¥·¡¼¥ó¤Ç²»¸»¤Îʬ´ô½èÍý¤¬¹Ô¤¨¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¥²¡¼¥à¤ò¼Â¹Ô¤·¤ÆÆ°ºî¤Î¸¡¾Ú¤ò¹Ô¤¤¤Þ¤·¤ç¤¦¡£¥²¡¼¥à¥¯¥ê¥¢»þ¤È¥²¡¼¥à¥ª¡¼¥Ð¡¼»þ¤ÎBGM¤¬ÊѲ½¤·¤Æ¤¤¤ì¤ÐÀ®¸ù¤Ç¤¹¡£
¤½¤Î¾ì¹çResult¥·¡¼¥ó¤Î¥Ò¥¨¥é¥ë¥¡¼¤ÎAudio¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ÎAudioSource¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ò¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤Ç³Îǧ¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
None¤Ç¤¢¤Ã¤¿AudioClipÍó¤Ë¡¢¼«Æ°Åª¤ËºÆÀ¸¤¹¤ë²»¸»¥Õ¥¡¥¤¥ë¤¬¥¢¥µ¥¤¥ó¤µ¤ì¤Æ¤¤¤ë¤Ï¤º¤Ç¤¹¡£¡Ê¤³¤ÎÎã¤Ç¤Ï¡¢¥²¡¼¥à¥¯¥ê¥¢»þ¤Ë¤ÏBGM3¡¢¥²¡¼¥à¥ª¡¼¥Ð¡¼»þ¤Ë¤ÏBGM4¤¬¥¢¥µ¥¤¥ó¤µ¤ì¤Þ¤¹¡Ë
¼Â¹ÔÁ°¤ÎAudioClip¡ÊNone¡Ë
![](https://image02.seesaawiki.jp/i/o/i-school-memo/G_OMoakVby-s.png)
¥²¡¼¥à¥¯¥ê¥¢»þ¤ÎAudioClip
![](https://image01.seesaawiki.jp/i/o/i-school-memo/mmC8HC23NM-s.png)
¥²¡¼¥à¥ª¡¼¥Ð¡¼»þ¤ÎAudioClip
![](https://image01.seesaawiki.jp/i/o/i-school-memo/i6UD1L76YS-s.png)
¡¡½èÍý¤¬¤¦¤Þ¤¯¤¤¤«¤Ê¤¤¾ì¹ç¤Ë¤ÏDebug.Log¤ÇisGameClear¤ÎÃͤ¬¤É¤Î¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤«¡¢isGameClear¤ÎÃͤò»È¤Ã¤¿Ê¬´ô½èÍý¤Ë½ñ¤´Ö°ã¤¤¤Ï¤Ê¤¤¤«¤ò³Îǧ¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- Áí¹ç
¥³¥á¥ó¥È¤ò¤«¤¯