å ã®èª²é¡ãžã®ãªã³ã¯ã¯æ¬¡ã®ãšããã§ããwww.unity3dstudent.com / 2010/07 / challenge-c03-beginner
çµè«ïŒãã¬ãŒã€ãŒã¯å·Š/å³ã«ç§»åãã3ã€ã®ã¿ãŒã²ããã§å°æã§ããå¿ èŠããããŸãã ãããããå Žåãã¿ãŒã²ããã¯èœäžããªããã°ãªããããã¬ã€ã€ãŒã¯ãããããšã«ãã€ã³ããç²åŸããŸãã 3ç¹ã«éãããšãã²ãŒã çµäºç»é¢ã衚瀺ãããŸãã
æåã®ã¿ã¹ã¯ã
2çªç®ã®ã¿ã¹ã¯ã
ããŒã1ïŒã·ãŒã³ã
ã·ãŒã³ã«å¹³é¢ãè¿œå ããŸã-ã¿ãŒã²ãããã¥ãŒãã眮ãããåºã§ããçŸæç¹ã§ã¯ãµã€ãºãå€æŽããŸããã ãã¬ã€ã€ãŒãã«ã¡ã©ã®äœçœ®ããèŠãŠããæ¹åãšåãæ¹åã«æ®åœ±ãããšããŸãã ç°¡åã«ããããã«ãOX軞ã«æ²¿ã£ãŠæ®åœ±ãããšããŸãïŒè»žã®æ¹åã¯ã[ã·ãŒã³]ã¿ãã®å³äžé ã«è¡šç€ºãããããšãæãåºããŠãã ããïŒã
ããã«å¿ããŠã«ã¡ã©ãé 眮ããŸãã ã¹ããŒãžäžã®å¹³é¢ãéžæããŸãã OX軞ïŒäžã®æåã®ã¹ã¯ãªãŒã³ã·ã§ããã®å¯Ÿå¿ããã³ãŒã³ãã¿ã³ïŒãã¯ãªãã¯ãããšãéžæãããªããžã§ã¯ãïŒã€ãŸããå¹³é¢ïŒãOX軞ã«å¹³è¡ãªæ¹åã«ãèŠããããšãã§ããŸãïŒ2çªç®ã®ã¹ã¯ãªãŒã³ã·ã§ãããåç §ïŒã
ã¹ã¯ãªãŒã³ã·ã§ãã1
ã¹ã¯ãªãŒã³ã·ã§ãã2
é£è¡æ©èªäœãèŠããªããªãã®ãé©ããªãã§ãã ãããããã§ããã¹ãã§ãã 次ã«ãã«ã¡ã©ãåãäœçœ®ã«é 眮ããŸããéå±€ããã«ã§ã¡ã€ã³ã«ã¡ã©ãªããžã§ã¯ããéžæããGameObject-> Align With Viewãã¯ãªãã¯ããŸãïŒãŸãã¯Ctrl + Shift + FãæŒããŸãïŒã ããã§ãæã¿ã®é è¿æã§ã«ã¡ã©ããå¹³é¢ãèŠãããšãã§ããŸãããé ãã«ãããã«ã¡ã©ãäœãããŸãïŒ[ã·ãŒã³]ã¿ãã®å³äžé ã«éžæããã«ã¡ã©ãªããžã§ã¯ãããã-ã«ã¡ã©ãã¥ãŒããã¬ãã¥ãŒããŸãïŒã ä»ã®ãšããããµãŒã¯ã«ã«æ³šæãæã£ãŠã¯ãããŸããã
ã·ãŒã³ã®ãéåžžã®ããã¥ãŒã«æ»ããŸãããããããè¡ãã«ã¯ãã¹ããŒãžäžã§å¹³é¢ãéžæããå³äžé ã®è»žç¢å°ã®éã®ç«æ¹äœãã¯ãªãã¯ããŸãïŒæ£æ¹åœ¢ãšããŠè¡šç€ºãããŸãïŒãäžã®ã¹ã¯ãªãŒã³ã·ã§ããã§ã¯èµ€ã§å²ãŸããŠããŸãã 次ã®ãããªãã®ã衚瀺ãããŸãïŒã«ã¡ã©ãèŠããããã«ããŠã¹ãã€ãŒã«ãåããŠé£è¡æ©ããé¢ããå¿ èŠãããå ŽåããããŸãïŒã
ã«ã¡ã©ã¯ã¹ã¯ãªãŒã³ã·ã§ããã§åŒ·èª¿è¡šç€ºãããŸãã
次ã«ãã«ã¡ã©ãé«ãäžããŠå¹³é¢ã«ç§»åããŸãïŒå¹³é¢ã®è¿ãã®ç«¯ãèŠããªãããã«ããããšãå¯èœã§ãïŒã
ããã¯ãã¹ãŠã«ã¡ã©ã§ãã ã·ãŒã³ã«ç §æãè¿œå ãã-ç¹å æºïŒä»ã®å æºã䜿çšã§ããŸããããã§ã¯ãç §æãè¿œå ããç®çã¯ãåã«ã·ãŒã³ããæãããããããšã§ããçŸããç §æã®å Žåã¯ãä»ã®å æºã䜿çšããå¿ èŠããããŸãïŒã
ç¹å æºã«ã¯ããã€ãã®ç·šéå¯èœãªãã©ã¡ãŒã¿ãŒããããŸãã ç¹ã«ã匷床ãšç¯å²ã«èå³ããããŸãã æåã®å 匷床ã¯ãå æºãã©ã®ããã«æããèŒããã決å®ããŸãã 2çªç®ã¯ç¯å²ã§ãã ã€ãŸããå æºã¯éåžžã«æããèŒãããšãã§ããŸãããã»ãã®ãããã§ãã ãããŠãIntensityãã©ã¡ãŒã¿ãŒããããå€æŽããŠããå æºããã®å ã¯æå®ãããååŸãè¶ ããŠäŒæããŸããã
ããã©ã«ãã§ã¯ããã©ã¡ãŒã¿ã¯ç¯å²= 10ããã³åŒ·åºŠ= 1ã«èšå®ãããŠããŸãå æºã®ãªããžã§ã¯ããéžæãããšããã®åšå²ã®ã¹ããŒãžã®åšãã«ããŒã«ãæãããŸã-ããã¯å æºããèŒããããªã¥ãŒã ã§ãã ç§ã®å Žåãé£è¡æ©ã¯ãã®ããªã¥ãŒã å ã«ãã£ãã®ã§ãç¯å²ã¯å€æŽã§ããŸããã§ããããé£è¡æ©ã¯ãªããšãªãèæãç §ããããŠããã®ã§ã匷床ã4ã«å¢ãããŸããïŒäžã®ã¹ã¯ãªãŒã³ã·ã§ããã§ã¯ãããã¯æ¢ã«è¡ãããŠããŸãïŒã
次ã«ããããžã§ã¯ãããã«ã§ã¿ãŒã²ããã®ãã¬ãããäœæããã¿ãŒã²ãããšåŒã³ãŸãïŒãã¡ããã3ã€ã®åå¥ã®ãªããžã§ã¯ãã§å®è¡ã§ããŸãããããã¯äžäŸ¿ã§ãã3ã€ã§ã¯ãªãã100ã®ã¿ãŒã²ãããå¿ èŠãªå Žåã¯ã©ãã§ããããïŒã ã·ãŒã³ã«ãã¥ãŒããè¿œå ããŸãã ãã¯ã¹ãã£ãè¿œå ããŠãå°ãè²ãä»ããŸãã ååã®åæã§ã¯ããã¯ã¹ãã£ã䜿çšããŠãããªã¢ã«ãäœæããŸããããããäžåºŠäœ¿çšããŠã¿ãŸãããïŒ ãããªã¢ã«ã®äœææ¹æ³ãèŠããŠããªãå Žåã¯ãåã®ã¿ã¹ã¯ã®åæãèŠãŠãã ããã
次ã«ãéå±€ããã«ããããã®ãã¥ãŒãããããžã§ã¯ãããã«ã®ãã¬ããã«ãã©ãã°ãããã¥ãŒããåé€ããŸãã ãã¬ããã®3ã€ã®ã³ããŒïŒãŸãã¯ããµã³ãã«ããè±èªã§ã¯ãç解ããŠãããšãããããã¯ã€ã³ã¹ã¿ã³ã¹ãšåŒã°ããŸãïŒãäœæããŸãããã ãããããã¹ãŠã«ã¡ã©ãšã»ãŒåãé«ãã«é 眮ããŸãããïŒ
ã¿ãŒã²ããã®äœçœ®ã¯ããã¬ã€ã€ãŒãã·ã¥ãŒããç¿åŸããåŸã§ãä¿®æ£ããããšãã§ããŸãïŒã¿ãŒã²ããããããããããšãäžå¯èœãªå ŽåïŒã
ãããŸã§ãªãžããããã£ã³ã³ããŒãã³ããªãã§æã£ãŠããã¿ãŒã²ããã¯ããããããåã«èœäžããŠã¯ãªããªãããšã«æ³šæããŠãã ããã ãããŠãå¿ èŠã«å¿ããŠãããã«ãã®ã³ã³ããŒãã³ãããããã«è¿œå ããŸãïŒåãwww.unity3dstudent.comããã®ã¬ãã¹ã³ã§ã¯ããã®ãªãã·ã§ã³ã¯æé»çã«æäŸãããŸããå¥ã®æ¹æ³ã«ã€ããŠ-èšäºã®çµããè¿ãã第3éšïŒ
ã¡ã€ã³ã·ãŒã³ã®æºåãæŽããã²ãŒã ã®å®äºç»é¢ãåã³è¡šç€ºãããŸãã
ããŒã2ïŒã¹ã¯ãªããã
ãŸããå¿ èŠãªã¹ã¯ãªããã決å®ããŸãã
ãŸããã«ã¡ã©ã®ã¿ãŒã²ããäœçœ®ã§æ®åœ±ããå¿ èŠããããŸããåãã¹ã¯ãªããã§ïŒã«ã¡ã©èªäœã«ããã³ã°ããããŸãïŒãå·Šå³ã«ç§»åããŸãã ãã®ã¹ã¯ãªããã¯PlayerscriptãšåŒã°ããŸãã
ãŸããã¿ãŒã²ãããã¬ããã«ã¹ã¯ãªãããæ·»ä»ããå¿ èŠããããŸããããã«ãããã³ãªãžã§ã³äžã«Rigidbodyã³ã³ããŒãã³ããè¿œå ããããã¬ãŒã€ãŒãžã®ãã€ã³ããã«ãŠã³ããããŸãã ããã¯Rigidbodytizerã«ãªããŸãã
ãããã誰ãã¹ã³ã¢ãä¿æããŸããïŒ ã«ã¡ã©ã®ã¹ã¯ãªããã§ãããè¡ãããšã¯å¯èœã§ãããã©ããããããèŠèŠãããªããŸãã 空ã®ãªããžã§ã¯ããã·ãŒã³ã«è¿œå ãïŒGameObject-> Create EmptyïŒãGameManagerãšåŒã³ãŸããèç©ããããã€ã³ããã«ãŠã³ãããå¿ èŠã«å¿ããŠå¥ã®ã·ãŒã³ïŒã²ãŒã çµäºç»é¢ïŒã«ç§»åããŸãã ãã®ãªããžã§ã¯ãã«ã¯ç¬èªã®ã¹ã¯ãªãããå¿ èŠã§ããåããªããžã§ã¯ãGaââmeManagerãšåŒã°ããŸãã
ãŸããæåã«å¿ èŠãªãã®ãææ¡ããŸãããïŒGameManagerã¹ã¯ãªããã å®éãUpdateã¡ãœããã䜿çšããŠã¹ã³ã¢ããã§ãã¯ããçŸåšã®ã¹ã³ã¢ãšåã€ããã«ã¹ã³ã¢ãªã³ã°ããå¿ èŠããããã€ã³ãã®æ°ãæ ŒçŽããããã®å€æ°ãããã€ãå¿ èŠãšããŸãïŒãã¡ãããæ°å3ã䜿çšããŠååŸã§ããŸãããã²ãŒã ãå€æŽããå Žåã¯ãããã€ãã®äžäŸ¿ãçããŸãïŒã
using UnityEngine; using System.Collections; public class GameManager : MonoBehaviour { public uint neededScore = 3; public static uint score = 0; // Update is called once per frame void Update () { if (score == neededScore) { // } } }
ã¹ã³ã¢å€æ°ã¯public staticãšããŠèšè¿°ãããŸãããã®å ŽåãGameManager.scoreãšããŠä»»æã®ã¹ã¯ãªããããã¢ã¯ã»ã¹ã§ããããã§ãã ãã¡ãããã¢ã«ãŠã³ãã®å€ãæ ŒçŽãããå€æ°ããããªãã¯ã¡ã³ããŒã§ããããšã¯ããŸãè¯ããããŸããããã¹ã¯ãªããããžãã¯ãåçŽåããããã«ããã®ãŸãŸã«ããŠãããŸãããã äœæããã¹ã¯ãªãããGameManagerãªããžã§ã¯ãã«å¿ããã«æ·»ä»ããŠãã ããã
ããã§ã¯ãRigidbodytizerã¹ã¯ãªãããèŠãŠã¿ãŸãããã Updateã¡ãœãããStartã¡ãœããã¯å¿ èŠãããŸãããOnCollisionEnterïŒïŒã¡ãœãããè¿œå ããŸãã
void OnCollisionEnter() { if (rigidbody == null) { gameObject.AddComponent("Rigidbody"); GameManager.score++; } }
æ¡ä»¶ã¯ãRigidbodyã³ã³ããŒãã³ãããªããžã§ã¯ãã«æ¢ã«è¿œå ãããŠãããã©ããã確èªããè¿œå ãããŠããªãå Žåã¯è¿œå ããŠãåŸç¹ãå¢ãããŸãã ãã€ã³ãæ°ãå¢ããããšãæ¡ä»¶å ã«ããããšã«æ³šæããŠãã ããïŒ ãã以å€ã®å Žåããã€ã³ãã¯ããã¢ã§ã¿ãŒã²ããã«ãããããå Žåã§ãã«ãŠã³ããããŸãã 次ã«ãRigidbodytizerãã¿ãŒã²ãããã¬ããã«åãä»ããŸãã
ç¢å°-Playerscriptã¹ã¯ãªãããè¿œå ããŸãã ããããæåã«ãã匟䞞ãã®ãã¬ãããå¿ èŠã§ã-ããããæã¡ãŸãã 匟䞞prefpabããããžã§ã¯ãã«è¿œå ããçäœãã·ãŒã³ã«è¿œå ããŸãã åŸè ããã¹ãŠã®æ¬¡å ã§ããšãã°0.4ã®ãµã€ãºã«å§çž®ããŸããTransformã³ã³ããŒãã³ãã®ã€ã³ã¹ãã¯ã¿ãŒã§ããã¹ãŠã®Scaleãã£ãŒã«ãã®å€ã0.4ã«å€æŽããŸãã
ãããªã¢ã«ãšçãè¿œå ã§ããŸããããã¯ãªãã·ã§ã³ã§ãã çäœãéå±€ããã«ãããããžã§ã¯ãããã«ã®åŒŸäžžãã¬ããã«ãã©ãã°ããã·ãŒã³ããçäœãåé€ããŸãã
ã«ã¡ã©ãã©ã®ããã«ç§»åããŸããïŒ ããããåé¡ã¯ãã©ã®ããã«ãã§ã¯ãªãïŒå€æãå€æŽããŸããäœçœ®ã¯åé¡ã§ã¯ãããŸããïŒããäœã«å¿ããŠïŒãã§ãã Inputã¯ã©ã¹ã«ã¯ããã°ãããéçGetAxisã¡ãœããããããŸãããã®ã¡ãœããã¯ã軞ã®ååã«ãã£ãŠç¹å®ã®floatå€ãçæããŸãã ãHorizoâântalããšãVerticalãã®è¡ãå«ãããšã-1ãã1ã®å€ãåŸãããããããåçŽè»žãšæ°Žå¹³è»žããã®åå·®ã®åºŠåãã瀺ãããŸãã ããã¯ãããŒããŒãã®ç¢å°ãšWASDãããã³ãžã§ã€ã¹ãã£ãã¯ã§æ©èœããŸãã åæã«ããžã§ã€ã¹ãã£ãã¯ã§ã軞ããã®åå·®ãã«é¢ãããã¬ãŒãºã«æå³ãããå ŽåãããŒããŒãã§ã¯ãç解ããŠããããã«ãã»ãšãã©ã®å ŽåãããŒãæŒããããšãã«+1ãŸãã¯-1ïŒæ¹åã«å¿ããŠïŒãè¿ããŸãããæŒããšæ £æ§ããããŸãããŒãé¢ããŸãïŒInput.GetAxisã¡ãœããã«ãã£ãŠè¿ãããå€ã¯äžéå€ãééããŸãïŒã ãã®æ¹æ³ã®è©³çŽ°ã«ã€ããŠã¯ã ãã¡ããã芧ãã ãã ã
åä¿¡ããæ å ±ã䜿çšããŠãã«ã¡ã©ãåãããŸãã
public class Playerscript : MonoBehaviour { public const float speed = 7; public GameObject bulletPrefab; public float force = 1500; // Update is called once per frame void Update () { float translation = Input.GetAxis("Horizontal") * Time.deltaTime * speed; transform.position += new Vector3(0, 0, translation); } }
ãããªãã¯å¯å€é床ã¯ãã«ã¡ã©ã®æ倧é床ãæ åœããŸãã Input.GetAxisã«ãã£ãŠè¿ãããå€ã«Time.deltaTimeãä¹ç®ããããããã«ã¡ã©ã¯ããã¬ãŒã ãããã®ã¡ãŒãã«ãã§ã¯ãªããç§ãããã®é床ã¡ãŒãã«ãããéã移åããŸããã ãããŠbulletPrefabã¯ãç§ãã¡ãæã€åŒŸäžžã®åå ã§ãã force-ãã®ãŸãã«åŒŸäžžããæãããåã®ã¢ãžã¥ãŒã«ã
ã¹ã¯ãªãããã«ã¡ã©ã«ã¢ã¿ããããã·ãŒã³ãå®è¡ããŠãå·Š/å³ç¢å°ãæŒããŠã¿ãŠãã ããã ãã¹ãŠé 調ã§ããæ®åœ±ã®æéã§ãïŒ
Updateã¡ãœããã§ãžã£ã³ãããŒïŒããã©ã«ãã®ã¹ããŒã¹ïŒãæŒãããšãã«ã·ã§ãããè¿œå ããŸãã
if (Input.GetButtonDown("Jump")) { GameObject bullet = GameObject.Instantiate(bulletPrefab, transform.position, transform.rotation) as GameObject; bullet.rigidbody.AddForce(transform.forward * force); }
MainCameraãªããžã§ã¯ããéžæããPalyerscriptã³ã³ããŒãã³ãïŒã¹ã¯ãªããïŒã®Bullet Prefabãã£ãŒã«ãã®Inspectorããã«ã§å¿ããã«ãProjectããã«ããbullet Prefabããã©ãã°ããŠãã ããã
ã·ãŒã³ãå®è¡ã§ããŸã-ã²ãŒã ã®æºåã¯ã»ãŒå®äºããŠããŸãã ã²ãŒã ã®çµäºæã«å¥ã®ã·ãŒã³ã«ç§»è¡ããããšã¯æ®ã£ãŠããŸãã ãããè¡ãã«ã¯ãæåã«æ°ããã·ãŒã³ãäœæããã¢ã»ã³ããªçšã®ã·ãŒã³ã®ãªã¹ãã«å¿ ãå«ããå¿ èŠããããŸãã
ãããžã§ã¯ãã«æ°ããã·ãŒã³ãè¿œå ããããã«ãwinããšããååã§ä¿åããŸãã [ãã¡ã€ã«]-> [ãã«ãèšå®]ãéžæããŸãã 次ã«ã衚瀺ããããŠã£ã³ããŠã§[çŸåšã®è¿œå ]ãã¿ã³ãã¯ãªãã¯ããå¿ èŠããããŸãïŒ[ãããžã§ã¯ã]ããã«ãã[ãã«ãäžã®ã·ãŒã³]ãªã¹ãã«ã·ãŒã³ããã©ãã°ã§ããŸãïŒã ã¡ã€ã³ã«ã¡ã©ãªããžã§ã¯ãã®èæ¯è²ããã楜芳çãªãã®ã«å€æŽããŸãã
ããã§ãããã¹ããè¿œå ããå¿ èŠããããŸãïŒãYou winïŒããªã©ïŒã GameObject-> Create Other-> GUI Textãã¯ãªãã¯ããŸãã ããã©ã«ãã®ããã¹ããGui Textãã§æ°ãããªããžã§ã¯ãã衚瀺ãããŸãã GUITextã³ã³ããŒãã³ãã®Textãã£ãŒã«ããç®çã®ã³ã³ããŒãã³ãã«å€æŽãããã©ã³ããµã€ãºãå€æŽããŸãïŒFont Sizeãã£ãŒã«ãïŒã ãã ããããã¹ãã¯ç»é¢ã®äžå€®ã«ã¯ãããŸããã
ãã®ããã¹ãã®åäœã®çç±ãå³ã§åŒ·èª¿è¡šç€ºãããŠããŸãã Anchorããããã£ã¯ãããã¹ãã®ãäžå¿ããããå Žæã瀺ããŸãã ç©ççãªäžå¿ã§ã¯ãªããããã¹ãã®äœçœ®ã決å®ããäžå¿ã ãå·ŠäžããéžæãããŸãããã€ãŸããããã¹ãã¯å·Šäžé ã§ãäžæããããŠããŸãã ã芧ã®ãšããããã®ã³ãŒããŒã¯å®éã«ã¯ç»é¢ã®äžå€®ã«ãããŸãã ãäžå€®äžå€®ãã®å€ãéžæãããšãããã¹ãã¯ç»é¢äžå€®ã®é©åãªäœçœ®ã«ç§»åããŸãã
ãªãç»é¢ã®çãäžã«ãããããã¹ããã·ããããå¿ èŠãããå Žåã¯ã©ãããŸããïŒ GUITextã«ã¯ãXããã³Yãã£ãŒã«ããæã€ãã¯ã»ã«ãªãã»ãããã£ãŒã«ãã®ã°ã«ãŒãããããŸããå¿ èŠãªå€ãèšå®ããããšã«ãããç»é¢ã®äžå¿ïŒããæ£ç¢ºã«ã¯ãã²ãŒã ã®ãŠã£ã³ããŠã®äžå¿ïŒã«å¯ŸããŠæå®ãããã¯ã»ã«æ°ã ãããã¹ããã·ããã§ããŸãã
é©åãªã¿ã€ãã³ã°ã§ãã®ã·ãŒã³ã«ãã©ã³ãžã·ã§ã³ãè¿œå ããŸãã ã¡ã€ã³ã·ãŒã³ã«æ»ããGameManagerã¹ã¯ãªããã®Updateã¡ãœããã調æŽããŸãããã
void Update () { if (score == neededScore) { Application.LoadLevel("win"); } }
ããã«ãããç®çã®ã¹ã³ã¢ã«å°éãããšãæ°ããäœæãããã·ãŒã³ãããŒããããŸãã
ããã§äž»èŠéšåãçµäºããéåžžã«ãã¬ã€ãããããªããŸããã ãã¡ãããã¡ã€ã³ã·ãŒã³ã«çŸåšã®çµæã®ç¢æãè¿œå ãã䟡å€ã¯ãããŸãããããã¯å°ããªã¿ã¹ã¯ã§ã:) GUITextã³ã³ããŒãã³ããæã€ãªããžã§ã¯ãã®ããã¹ããžã®ã¢ã¯ã»ã¹ã¯æ¬¡ã®ããã«å®è¡ãããããšã«æ³šæããŠãã ããã
guiText.text = "Hello world!";
ããŒã3ïŒçŸåŠã
ãããŠåã³ãã·ãŒã³ã§äœããééã£ãŠãããšããæèŠïŒ ãŸãšããªåŒŸäžžãã¯ã©ãã·ã¥ãããšããŸãšããªãã¥ãŒãã¯ã©ããªããŸããïŒã³ã¢ã§ã¯ãªããã³ã¢ããããŸãïŒã ããã§ããé£ã³ç«ã¡ãŸãããïŒ ãããããªãä»ã¯é£ãã§ããªãã®ã§ããïŒ çãã¯éåžžã«è«ççã§ãã
OnCollisionEnterã¡ãœããã§ã¿ãŒã²ãããRigidbodyã³ã³ããŒãã³ãã«è¿œå ãããšãã«ãŒãã«ã¯æ¢ã« Rigidbodyã®ãªãã¿ãŒã²ãããšè¡çªããŠããŸãã ãããããããå°ããè¡çªãçºçããããšãã«åŒã³åºãããã¡ãœããã¯ãããŸããïŒ ãããã£ãŠãåé¡ã¯ç°¡åã«è§£æ±ºãããŸãã
æ¬è³ªçã«äœãèµ·ããã®ã§ããããïŒ ã¿ãŒã²ããã¯å®ã«æµ®ããŠããŸãã ããã¯ã©ã®ããã«å¯èœã§ããïŒ åœŒå¥³ã«è³ªéããªãå Žåã¯ïŒ ãããããããã¯èµ·ãããŸããã ãªã質éäžè¶³ãå¿ èŠãªã®ã§ããïŒ ãã®ãããå°çãžã®éåã¯èº«äœã«äœçšããŸããã ããã§å€åããã¯æ¶ããŸããïŒ
äœè«ã®å§ãŸãããçµãããŸã§ã®æåŸã®æ®µèœã§ã¯ãå®éã«ãããã®èæ ®äºé ã¯çãããŸããã ã¿ãŒã²ããã®ãã¬ããã«Rigidbodyã³ã³ããŒãã³ããè¿œå ãããšãããå¶ç¶ã«Use Gravityãã£ãŒã«ãã«æ°ä»ããŸããã ã ããç§ã¯éåã®ãŸãã«ã¹ã€ãããèŠã€ããŸããã
ãšããã§ãã²ãŒã ãéå§ãããšïŒäžèšã®æ®µèœã®ã¿ãå®è¡ããå ŽåïŒãé¢çœãå¹æãåŸãããŸããã¿ãŒã²ããã¯é£ã³æ£ããŸãããéåã®ããã«èœäžããŸããã
Rigidbodytizerã¹ã¯ãªãããå€æŽãããšããæ¥ãŸããïŒãã ããä»ã§ã¯ãã®ååãæ£åœåãããã®ã§ã¯ãããŸããïŒã
void OnCollisionEnter() { if (!rigidbody.useGravity) { rigidbody.useGravity = true; GameManager.score++; } }
ãŸããå¥ã®ããšã ããã§ãã²ãŒã ã¯æ¬¡ã®ããã«ãªããŸãã
觊ããã2çªç®ã®ãã€ã³ãã¯ãã«ã¡ã©ã³ã³ãããŒã«ã§ãã ã«ã¡ã©ã1æ¬ã®çŽç·ã«æ²¿ã£ãŠç§»åãããã ãã§ããã¥ãŒãã®äœçœ®ã«å€§ããªå¶éã課ããããŸãïŒãã¥ãŒããããã¯ããŠã³ããããšãã§ããŸãïŒã å·Šå³ã®åããšåæ§ã«ãäžäžã®åããè¿œå ããŸãïŒäœ¿çšããå¿ èŠããããŸã
Input.GetAxis("Vertical")
ïŒ ãã®åŸãã¿ãŒã²ãããã¥ãŒããèŠçå
ã®ã©ãã«ã§ãé
眮ããããšãã§ãããããã«å
¥ãããšãã§ããŸãã
çµè«ãšããŠãé£è¡æ©ã®äžã«ã®ã¿ã¿ãŒã²ãããé 眮ããå Žåãé£è¡æ©ã®å¢çç·ã«ãã£ãŠå·Šå³ã«ç§»åãå¶éããPlayerscriptã«å°ããªå€æŽãå ããããšãè«ççã§ããããšã«æ³šæããŠãã ããã ããã€ãã®å€æ°ãšStartã¡ãœãããè¿œå ããŸãïŒã³ãŒãã®èª¬æïŒïŒ
float zBoundMin, zBoundMax; // Z void Start() { // "Plane" Bounds planeBounds = GameObject.Find("Plane").collider.bounds; zBoundMin = planeBounds.min.z; // Z zBoundMax = planeBounds.max.z; // Z }
ãã¡ããããã¬ãŒã ããšã«Z座æšã®å¶éãåèšç®ã§ããŸãããããã¯éå¹ççã§ãããåºå®å¹³é¢ã®å Žåã¯æå³ããããŸããã
次ã«ãUpdateã¡ãœãããå€æŽããŸããããtransform.positionãã¯ãã«ãå€æŽããåŸãå¥ã®è¡ãè¿œå ããŸãã
transform.position = new Vector3(transform.position.x,transform.position.y, Mathf.Clamp(transform.position.z, zBoundMin, zBoundMax));
æ®å¿µãªãããtransform.positionãã¯ãã«ã®Z座æšãåå¥ã«å€æŽããããšã¯ã§ããŸããã Mathf.ClampïŒxãaãbïŒé¢æ°ã¯ãaãšbã®å€ã®éã§å§çž®ãããšxã®å€ãè¿ããŸãïŒã€ãŸããxãaããå°ããå Žåãé¢æ°ã¯aã®å€ãè¿ããŸãïŒ
äžäžã«ç§»åããå Žåã¯ãåæ§ã®æ¹æ³ã§ãã«ã¡ã©ãé£è¡æ©ã®äžã«è¡ãããé«ãããªãããšã確èªããŠãã ããã
ããŒã4ïŒæçµã
ãããã«XYZãè¿œå ãããšã©ããªããããšããåæ§ã®æšè«ã«ãããã²ãŒã ããã¹ãããå人ã®ã¢ã€ãã¢ã䜿çšããŠãã²ãŒã ã次ã®ããã«å€æŽããŸããã
èå³ãããã°ã説æã§ã
ããã§ã ããã§å®åŒåãããçŸåšã®ã¿ã¹ã¯ãããã³ãããã®äžé£ã®èšäºãçµäºããŸãã
ãŸãã