ãUnity1ããã¿ã³é·æ¼ãã§ã²ã¼ã¸(uGUIã®Image)ãæºããã¸ã£ã³ãåã¢ããï¼ãã¦ããã£ã¡ãã縦ã¹ã¯ãã¼ã«9ã
Unity5.1.1f1 Personal(2015å¹´6æ)
Â
ãã®ã³ã³ãã³ãã¯ããã¦ããã£ã¡ããã©ã¤ã»ã³ã¹ãã§æä¾ããã¦ãã¾ã
Â
ååã®ç¶ãã§ãã
Â
ä»åã¯ãã¸ã£ã³ããã¿ã³ãé·ãæ¼ãã°æ¼ãã»ã©ã¸ã£ã³ãåãå¼·ããªãæ©è½ãã¤ãããã¨æãã¾ããuGUIã®Imageãæ´»ç¨ãã¦ãç»é¢å³ä¸ã«ã¸ã£ã³ãåã²ã¼ã¸ãä½ãã¾ãï¼
Â
uGUIã«ã¤ãã¦ããç¥ãããæ¹ã¯ä»¥ä¸ã®ã¨ãã»ã³ã¹ããåç §ä¸ããã
Â
Â
Â
Â
ãç®æ¨ãã¸ã£ã³ããã¿ã³é·æ¼ãã§ã¸ã£ã³ãåãå¼·ãããï¼
Â
â ã¸ã£ã³ãå表示ç¨ã®GUIãç¨æãã
ä»åãuGUIã使ãã¾ãã
Â
 ã¾ãã¯Hierarchy>Create>UI>Imageãé¸æããç»å表示ç¨ã®GUIãä½æãã¾ãã
Â
Â
ä»åã¯Imageãï¼ã¤ä½æãã¦ä¸ãããããã¦ãBar1ã¨Bar2ã¨åã¥ãã¾ãããã
Â
Â
ä»å使ãç»åã¯ãã¡ãã§ãã
Â
Â
ãã¡ãã®ç»åãããã¸ã§ã¯ãæ¬ã«ãã©ãã°ï¼ãããããã
Â
ãã©ãã°ï¼ããããï¼
Â
ç¶ãã¦Barã®InspectorãããSpriteModeãMultipleã«è¨å®ããSpriteEditorãéãã¦ä¸ããã
Â
Â
å³ä¸ã«Sliceã¨ããã¨ãããã¯ãªãã¯ããTypeã¯Automaticã®ã¾ã¾ãSliceãã¦ä¸ããï¼
Â
Â
ããã¨ç»åãã2ã¤ã®ãã¼ã«ã«ããããã¾ãã
Â
Â
ãã®ã¾ã¾SpriteEditorãéãã¦ãApplyãã¦ãã ããã
Â
Â
ããã§ã¯Bar1ã®è¨å®ãããã¦ããã¾ããBar1ã®Inspectorãã¥ã¼ãéãã¦ä¸ããã
Â
ã¾ãã¯RectTransformã«ããåè§ãããã¯ã¹ãã¯ãªãã¯ããAnchorPresetã®è¨å®ããã¦ä¸ãããå³ä¸ãé¸æããaltãæ¼ããã¾ã¾ã¯ãªãã¯ããã¨Anchorãå³ä¸ã«è¨å®ãããã¸ã·ã§ã³ãåæã«å¤æ´ãã¦ããã¾ãã
Â
Â
ä»ã®RectTransformã®è¨å®ã¯ä»¥ä¸ã®éãã§ããPivotã®Xã0ã«ãªã£ã¦ããç¹ã ã注æãã¦ä¸ãããããã¦ãImage(Script)ã®SourceImageã«ããã³ã¯ã®ãã¼ç»åãæå®ãã¦ä¸ããã
Â
Â
ãã¼ãåºç¾
Â
ãããªæãã«ãå³ä¸ã«Barã®Spriteç»åã表示ããã¾ãããåãè¦é ã§ããã²ã¨ã¤bar2ã®è¨å®ããã¦ããã¾ãããï¼
Â
Bar2ãä¸
Â
GUIã®æç»é ã¯ãä¸ã«ãããã®ã»ã©ä¸ã«è¡¨ç¤ºããã¾ããã§ãã®ã§ããã£ãä½ã£ãBar1ãä¸ã«ãããããè¨å®ãã¦ããBar2ãä¸ã«ç½®ãã¾ãããï¼
Bar2ã®è¨å®ã¯Bar1ã¨ã»ã¼ä¸ç·ã§ãã
Â
Bar2ã®Inspectorè¨å®
Â
Bar2ãBar1ã«é ãã¦ãããããç»é¢ã«å¤åã¯ããã¾ããã
Â
Â
Bar1ã®Widthã0ã«ãã¦ã¿ã¾ãããã
Â
Bar2åºç¾
Â
æ´ã«Bar1ã®Widthã90ã«ãã¦ã¿ã¾ãããã
Â
Â
90ã ã左端ããã²ã¼ã¸ã表示ããã¾ãï¼
Bar1ã®RectTransformã§ãPivotã®Xã0ã«ãããã¨ãè¦ãã¦ããã§ãããããããã«ãããç»åã®åºç¹ã左端ã«ãªããå·¦ããå³ã¸ç»åã伸ã³ãããã«ãªã£ãæãã§ãã
Â
次ã¯ã¹ã¯ãªããã§ããç»åã®Widthã¨jumpPowerå¤æ°ãé¢é£ããã¦ããã¾ãã
Â
â¡é·æ¼ãã§è²¯ããã¸ã£ã³ããã¯ã¼åãä¸ã«åãå ãã
é·æ¼ãã¯ãInput.GetMouseButtonã¨ããæ©è½ã使ãã¾ããæ¼ãç¶ãã¦ããéãå¦çãè¡ãç¶ãã¾ãï¼
Â
ä¼¼ã種é¡ã®ãã®ã«Input.GetButtonDownï¼ãã¿ã³ãæ¼ããç¬éï¼ã¨ãInput.GetButtonUpï¼ãã¿ã³ãæ¾ããç¬éï¼ã¨ããã¡ã½ãããããã¾ããï¼ä½è«ï¼
Â
ä»åã¯ã1ãã¬ã¼ã ã«ã¤ã4ãã¤å¢ããã300以ä¸ã«ãªã£ãæã¸ã£ã³ãåã0ã«æ»ãã¨ããå¦çãä½ãã¾ãã以ä¸ã½ã¼ã¹ã§ãï¼
Â
Â
ãã®BarScriptã¯Bar1ã«ä»ãã¦ä¸ããã
Â
publicå¤æ°playerScriptãä½æããã®ã§ãPlayerãªãã¸ã§ã¯ããæå®ãã¾ãã
Â
ãã©ãã°ï¼ããããï¼
Â
ã¾ãã¯Startã¡ã½ããã§RectTransformã³ã³ãã¼ãã³ããåå¾ãã¦ãã¾ããããã§ãBar1ã®RectTransformãã¹ã¯ãªããä¸ã§ä½¿ç¨ã§ããããã«ãªãã¾ããã
Â
次ã«Input.GetMouseButton(0)ï¼ã¯ãªãã¯ä¸ã§ããï¼ä¸ã¤ãplayerScript.isGroundedï¼ã¦ããã£ã¡ãããå°é¢ã«ä»ãã¦ããï¼æãã¸ã£ã³ãåã²ã¼ã¸ãå¢ãã¾ãã
isGroundedå¤å®ã追å ããªãã¨ãã¸ã£ã³ãä¸ãã¯ãªãã¯ãç¶ããã°ã²ã¼ã¸ãæºã¾ã£ã¦ãã¾ãã®ã§ã注æã§ãã
Â
ç»åãµã¤ãºãå¤æ´ããæã¯ãRectTransformã®sizeDeltaã§è¨å®ãã¾ããä¸èº«ã¯Vector2å(x, y)ã§ãã
Â
ã²ã¼ã¸ã®æ¨ªå¹ ã300ãè¶ ããã0ã«æ»ãã¾ãå¢ããã¨ããã«ã¼ããããã¦ããã¾ãã
Â
Input.GetMouseButtonUp(0)ï¼ã¯ãªãã¯ãé¢ãï¼ã®æ¡ä»¶ãæºãããæãPlayerScriptã®Jumpã¡ã½ããã¸ãã¸ã£ã³ãåã²ã¼ã¸ã®ãµã¤ãºï¼0ã300)ã2.5åããï¼0ã700ï¼ã¸ã£ã³ãåã渡ãã¦ããã¾ãã
Â
ã¸ã£ã³ããçµãã£ãããã¸ã£ã³ãåã²ã¼ã¸ã0ã«æ»ãã¾ãã
Â
ã¾ããã¸ã£ã³ãã²ã¼ã¸ãæºãã¦ãªããã¸ã£ã³ãããåã«è½ã¡ãã¨ããã±ã¼ã¹ãèããããã®ã§ãunityChanControllerã®isGroundedãfalseã ã£ãå ´åãã²ã¼ã¸ã0ã«æ»ãã¾ãã
Â
ç¶ãã¾ãã¦ãPlayerScriptãå çä¿®æ£è´ãã¾ãã
Â
Â
BarScriptããã¢ã¯ã»ã¹ã§ããããã«ãisGroundedå¤æ°ã¨Jumpã¡ã½ãããpublicã«ãã¾ããã¾ããjumpForceãåãåãããã«å¼æ°ã追å ãã¾ãã
Â
ä¸è¦ã«ãªã£ãjumpForceå¤æ°ã¨ãUpdateã¡ã½ããå ã®Jumpã¡ã½ããã®å¼ã³åºãã¯åé¤ãã¦ããã¦ä¸ããã
Â
 ãçµæã
Â
é·æ¼ãã§ã²ã¼ã¸ãå¢ããã²ã¼ã¸ã®é·ãã«ãã£ã¦ã¸ã£ã³ãåãå¤ãã£ã¦ãã¾ãã
Â
ä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
Â