ãUnity2ãuGUIã§ã²ã¼ã ãªã¼ãã¼ã¨ã¯ãªã¢ç»é¢ãä½æ(å¾ç·¨)ï¼SendMessage, Application.LoadLevelããããã¯å´©ã5ã
Unityãã¼ã¸ã§ã³ï¼5.0.0f4 Personal(2015å¹´4æ)
Â
ååã®ç¶ãã§ããÂ
ã¿ã¤ãã«ç»é¢ããã²ã¼ã ç»é¢ã¸ç¡äºé·ç§»ã§ãã¾ããï¼
Â
æ®ã課é¡ã¯
ã»ãã¼ã«ãç»é¢ä¸ã¸è¡ã£ãæãã²ã¼ã ãªã¼ãã¼ç»é¢ã«ãã
ã»ã²ã¼ã ãªã¼ãã¼ç»é¢ã§å度ã¯ãªãã¯ããã¨ãã¿ã¤ãã«ç»é¢ã¸æ»ã
ã»ãããã¯ãå ¨ã¦æ¶ãã¨ã²ã¼ã ã¯ãªã¢ã¼ç»é¢ã¨ãªã
ã»ã²ã¼ã ã¯ãªã¢ã¼ç»é¢ã§å度ã¯ãªãã¯ããã¨ãã¿ã¤ãã«ç»é¢ã¸æ»ã
ãããªæãã§ãããã²ã¨ã¤ãã¤è¦ã¦ããã¾ããã
ãç®æ¨ãã²ã¼ã ãªã¼ãã¼ã¨ã¯ãªã¢ãè¨å®ãã¦ãã²ã¼ã ãå®å ¨ã«åã
Â
 ã課é¡ï¼ããã¼ã«ãç»é¢ä¸ã¸è¡ã£ãæãã²ã¼ã ãªã¼ãã¼ç»é¢ã«ãã
 ããã§ã¯ã¾ããGUIã®è¨å®ããè¡ãã¾ããããHierarchyããCreate>UI>Textãé¸æãã¦ä¸ããã
Â
åååæ§Canvasã®CanvasScalerã®è¨å®ããè¡ãã¾ãã
Â
ååã¨å ¨ãåãè¨å®
Â
Textã®ååãGameOverã«å¤æ´ãã¾ãã
Â
Â
ååã®è¨äºã®è¦é ã§ãGameOverã®æåãçãä¸ã«æ¥ãããã«RectTransformããæåãããæãã«ãªãããã«Text(Script)ãè¨å®ãã¦ããã¾ãã
Â
åã¯ãããªæãã«è¨å®ãã¾ãã
Â
ãããªæãã®ãã¸ã·ã§ãã³ã°
Â
ä»ã®ã¾ã¾ã§ã¯GameOverã®æåãåºã£ã±ãªããªã®ã§ãæåã®è¡¨ç¤º/é表示ã«ã¤ãã¦èª¬æãã¾ããã¾ãã¯scriptã
Â
Â
ãã®GameOverScriptããCanvas>GameOverãªãã¸ã§ã¯ãã«è²¼ãä»ãã¦ä¸ããï¼
Â
ã²ã¼ã ã¹ã¿ã¼ãæã« ããã¹ããç¡å¹ã«ãã¦é表示ã«ãããã¼ã«ãç»é¢ä¸ã¸è¡ãè² ããæã«Loseã¡ã½ãããå®è¡ããããã«ãªã£ã¦ããã¾ããLoseã¡ã½ããã®å®è¡æ¹æ³ã¯èª²é¡ï¼ã«ã¦ã
Â
ã課é¡ï¼ãã²ã¼ã ãªã¼ãã¼ç»é¢ã§å度ã¯ãªãã¯ããã¨ãã¿ã¤ãã«ç»é¢ã¸æ»ã
ããã§ã¯ç¶ãã¦ã²ã¼ã ãªã¼ãã¼å¤å®ç¨ã®ãBottomScriptã§ãã
Â
Â
ã¾ãã¯ãã®scriptãç»é¢æä¸é¨ã«ããå£ï¼Bottomã¨åä»ãã¾ããï¼ã«è²¼ãä»ãã¦ä¸ããã
Â
ããã¤ã§ã
Â
BottomScriptã«gameOverã¨ããGameObjectãpublicã§ä½æãã¦ãããã®ã§ãä½æããGameOverã®GUIãªãã¸ã§ã¯ãããã©ãã°ï¼ãããããã¾ãï¼
Â
ãã©ãã°ï¼ããããï¼
Â
ããã§ãã¼ã«ãBottomã«ã¶ã¤ãã£ãæã«ãã¼ã«ãæ¶æ» ããSendMessageã«ããGameOverScriptã®Loseã¡ã½ãããå®è¡ãããã¨ã«ããGameOverã®æåã表示ãããgoTitleãtrueã«ããçµæUpdateã¡ã½ããå ãæå¹ã«ãªããæ´ã«ãã®ç¶æ ã§ç»é¢ãã¯ãªãã¯ããã¨ã¿ã¤ãã«ã¸æ»ãã·ã¹ãã ãã§ããããã¾ããï¼
Â
ã課é¡ï¼ã ãããã¯ãå ¨ã¦æ¶ãã¨ã²ã¼ã ã¯ãªã¢ã¼ç»é¢ã¨ãªã
ã課é¡ï¼ãã²ã¼ã ã¯ãªã¢ã¼ç»é¢ã§å度ã¯ãªãã¯ããã¨ãã¿ã¤ãã«ç»é¢ã¸æ»ã
ç¶ãã¾ãã¦ãããã¯ãå ¨ã¦æ¶ããæã«GameClearã¨ãªãè¨å®ãè¡ãã¾ããã¾ãã¯GUIãä½æãã¾ããããHierarchy>Create>UI>Textãé¸æããååãGameClearã«å¤æ´ãã¾ãï¼
Â
RectTransformã¨Text(script)ã®è¨å®ã¯åºæ¬çã«GameOverã¨åãã§ããã§ãããããã§ã¨ãæãåºãããã«é»è²ã«è²ä»ããã¾ããã
Â
Colorã§è¨å®
Â
ç¶ãã¦scriptã§ããã¡ã½ããåãWinã«ããã ãã§GameOverScriptã¨å ¨ãåãã§ãï¼
Â
Â
Â
ããã§ã¯ãã®Winã¡ã½ãããå¼ã³åºãããã®Scriptãã2-2ã®è¨äºã§æ¸ããBallScriptã«å çãã¾ããããÂ
Â
Â
#7ã«ã¦å¤æ°ã¨ãã¦ãBlockCntï¼ãããã¯ã«ã¦ã³ãï¼ã20ã§è¨å®ãã¦ãã¾ãã
Â
ããã¦OnCollisionEnterã«ã¦Blockã¿ã°ã®ä»ãããªãã¸ã§ã¯ãã«ãã¼ã«ãå½ãã度ã«ãããã¯ã«ã¦ã³ãã-1ãã¦ãã¾ããããã¦ãUpdateã¡ã½ããã«ã¦ãããã¯ã«ã¦ã³ãã0ã«ãªã£ãæã«ããã¼ã«ã®åããæ¢ããGameClearScriptã®Winã¡ã½ãããå®è¡ãGameClear!ã®æåã表示ãã¦ãã¾ããæå¾ã«ãGameClearç¶æ ã§ã¯ãªãã¯ããã¨ã¿ã¤ãã«ã¸æ»ãããã«ãªã£ã¦ããã¾ãã
Â
BallScriptã®GameClearæ¬ã«ãGameClearãªãã¸ã§ã¯ãããã©ãã°ï¼ãããããã¾ãããã
Â
ãã©ãã°ï¼ããããï¼
Â
æå¾ã«Prefabãã©ã«ãã«ãããããã¯ã®Prefabã«Blockã¿ã°ãä»ãã¦ã¿ã°ãä»ãã¾ãããã
Â
prefabãã©ã«ãã®ãããã¯ãé¸æ
Â
Inspector>Tag>Add Tagãé¸æ
Â
ãã©ã¹ã§ä½æ>Tag0ã«Blockã¨æ¸ãè¾¼ã
Â
å度ãããã¯Prefabãéãä½æããBlockã¿ã°ãä»ãã
Â
ããã§ã²ã¼ã ãªã¼ãã¼ã¨ã²ã¼ã ã¯ãªã¢ã¼ãæ©è½ããã¯ãã§ãã
ã²ã¼ã ãªã¼ãã¼
Â
ã²ã¼ã ã¯ãªã¢ã¼
Â
ã©ã¡ããã¿ã¤ãã«ç»é¢ã¸æ»ã
Â
ã²ã¨ã¾ãå½¢ã«ãªã£ããã¨æãã¾ããè¦ã¦ä¸ãã£ãçæ§ãé·ããã¨ãããã¨ããããã¾ããï¼
Â