ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2023ǯ06·î01Æü(ÌÚ) 14:45:06ÍúÎò
¡¡¥¯¥é¥¹¤Îʬ³ä¤Ï¡¢¥×¥í¥°¥é¥à¤Î²ÄÆÉÀ¤ÈÊݼéÀ¤ò¸þ¾å¤µ¤»¡¢¥Ð¥°¤ÎȯÀ¸¤ò¸º¤é¤¹¤¿¤á¤Î½ÅÍפʵ»½Ñ¤Ç¤¹¡£
¡¡¤Þ¤º¤Ï¡¢Ã±°ì¤Î¥¯¥é¥¹¤¬Ê£¿ô¤Î¥¿¥¹¥¯¤ò°·¤¦°Ê²¼¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤ò¹Í¤¨¤Æ¤ß¤Þ¤·¤ç¤¦¡£¤³¤³¤Ç¤Ï¡¢¥¹¥³¥¢¤Î´ÉÍý¤Èɽ¼¨¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹
using UnityEngine; using UnityEngine.UI; public class ScoreDirector : MonoBehaviour { // ¥¹¥³¥¢¤òÊݸ¤¹¤ëÊÑ¿ô private int score = 0; // ¥¹¥³¥¢¤Ë²Ã»»¤¹¤ëÃͤòÊÝ»ý¤¹¤ëÊÑ¿ô [SerializeField] private int point = 0; // ¥¹¥³¥¢É½¼¨ÍѤÎText¥³¥ó¥Ý¡¼¥Í¥ó¥È [SerializeField] private Text scoreText; // ¥¹¥³¥¢¤ò²Ã»»¤¹¤ë¥á¥½¥Ã¥É public void AddScore(int amount) { score += amount; Debug.Log("Score added. Current score: " + score); } // ¥¹¥³¥¢¤òɽ¼¨¤¹¤ë¥á¥½¥Ã¥É public void DisplayScore(int score) { scoreText.text = "Score: " + score; // ¥¹¥³¥¢¤ò¥Æ¥¥¹¥È¤Çɽ¼¨ ¡¡¡¡¡¡¡¡Debug.Log("Your total score is: " + score); } void Start() { // ¥Ç¥Ð¥Ã¥°ÍÑ AddScore(point); DisplayScore(score); } }
¡¡¤³¤ÎScoreDirector¥¯¥é¥¹¤Ç¤Ï¡¢¥¹¥³¥¢¤Î²Ã»»¤Èɽ¼¨¤ò´ÉÍý¤·¤Æ¤¤¤Þ¤¹¡£
scoreÊÑ¿ô¤Ï¥¹¥³¥¢¤òÊÝ»ý¤·¡¢AddScore¥á¥½¥Ã¥É¤Ï¥¹¥³¥¢¤ò²Ã»»¤·¡¢DisplayScore¥á¥½¥Ã¥É¤Ï¥¹¥³¥¢¤òɽ¼¨¤·¤Þ¤¹¡£
¡¡°ì¸«¡¢¤¹¤Ù¤Æ¤¬À°Íý¤µ¤ì¤Æ¤¤¤Æ¼êº¢¤Ê¤è¤¦¤Ë¸«¤¨¤Þ¤¹¤¬¡¢¥¯¥é¥¹¤¬Â礤¯¤Ê¤ê»Ï¤á¤ë¤ÈÌäÂ꤬À¸¤¸¤Þ¤¹¡£
¡¡¥¯¥é¥¹¤¬Â礤¯¤Ê¤ë¤È¡¢¤½¤ì¤Ï¥³¡¼¥É¤Î´ÉÍý¤¬Æñ¤·¤¯¤Ê¤ë¤³¤È¤ò°ÕÌ£¤·¤Þ¤¹¡£
ÆÃÄê¤Î¥á¥½¥Ã¥É¤ò¸«¤Ä¤±¤ë¤Î¤¬º¤Æñ¤Ë¤Ê¤ê¡¢¤Þ¤¿¡¢ÆÃÄê¤ÎÊÑ¿ô¤¬¤É¤Î¥á¥½¥Ã¥É¤Ë±Æ¶Á¤òÍ¿¤¨¤ë¤«ÇÄ°®¤¹¤ë¤Î¤âÆñ¤·¤¯¤Ê¤ê¤Þ¤¹¡£
¤½¤Î·ë²Ì¡¢¥Ð¥°¤¬È¯À¸¤·¤ä¤¹¤¯¤Ê¤ê¡¢¥Ç¥Ð¥Ã¥°¤âº¤Æñ¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¤µ¤é¤Ë¡¢Â礤ʥ¯¥é¥¹¤ÏºÆÍøÍÑÀ¤âÄã²¼¤·¤Þ¤¹¡£
°ìÉô¤Îµ¡Ç½¤À¤±¤¬Ê̤ξì½ê¤ÇɬÍפʾì¹ç¤Ç¤â¡¢¤½¤ÎÂ礤ʥ¯¥é¥¹Á´ÂΤòºÆÍøÍѤ¹¤ë¤³¤È¤Ë¤Ê¤ê¡¢É¬Íפʤ¤µ¡Ç½¤Þ¤Ç´Þ¤Þ¤ì¤Æ¤·¤Þ¤¤¤Þ¤¹¡£
¡¡¤·¤¿¤¬¤Ã¤Æ¡¢¥¯¥é¥¹¤òŬÀÚ¤Ëʬ³ä¤¹¤ë¤³¤È¤Ç¡¢¤³¤ì¤é¤ÎÌäÂê¤ò·Ú¸º¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
¼¡¤Î¥Ñ¡¼¥È¤Ç¤Ï¡¢¤³¤Î¥¯¥é¥¹¤ò¤É¤Î¤è¤¦¤Ëʬ³ä¤¹¤ë¤«¤ò²òÀ⤷¤Þ¤¹¡£
¡¡¥¹¥³¥¢¤Î²Ã»»¤Èɽ¼¨¤ò°ì¤Ä¤Î¥¯¥é¥¹¤Ç´ÉÍý¤¹¤ë¥µ¥ó¥×¥ë¥³¡¼¥É¤ò¸«¤Þ¤·¤¿¡£
º£²ó¤Ï¤³¤Î¥¯¥é¥¹¤ò£²¤Ä¤Ëʬ³ä¤·¡¢³Æ¥¯¥é¥¹¤¬°ì¤Ä¤ÎÌò³ä¤À¤±¤ò»ý¤Ä¤è¤¦¤Ë¤·¤Þ¤¹¡£
¡¡ScoreManager¥¯¥é¥¹Æâ¤Ë¤¢¤Ã¤¿½èÍý¤ò¾¤Î¥¯¥é¥¹¤Ë°Ñ¾ù¤·¡¢¥¹¥³¥¢¤Î²Ã»»¤Èɽ¼¨¤òÄ´À°¤·¤Þ¤¹¡£
¡¡¤Þ¤º¡¢¥¹¥³¥¢¤Î´ÉÍý¤òôÅö¤¹¤ëScore¥¯¥é¥¹¤òºîÀ®¤·¤Þ¤¹¡£
using UnityEngine; public class Score : MonoBehaviour { // ¥¹¥³¥¢¤òÊݸ¤¹¤ëÊÑ¿ô private int score = 0; // ¥¹¥³¥¢¤ò²Ã»»¤¹¤ë¥á¥½¥Ã¥É public void AddScore(int amount) { score += amount; } // ¸½ºß¤Î¥¹¥³¥¢¤ò¼èÆÀ¤¹¤ë¥á¥½¥Ã¥É public int GetScore() { return score; } }
¡¡¼¡¤Ë¡¢¥¹¥³¥¢¤Îɽ¼¨¤òôÅö¤¹¤ëScoreDisplay¥¯¥é¥¹¤òºîÀ®¤·¤Þ¤¹¡£
using UnityEngine; using UnityEngine.UI; public class ScoreDisplay : MonoBehaviour { // ¥¹¥³¥¢¤òɽ¼¨¤¹¤ë¤¿¤á¤ÎText¥³¥ó¥Ý¡¼¥Í¥ó¥È public Text scoreText; // ¥¹¥³¥¢¤òɽ¼¨¤¹¤ë¥á¥½¥Ã¥É public void DisplayScore(int score) { scoreText.text = "Score: " + score; // ¥¹¥³¥¢¤ò¥Æ¥¥¹¥È¤Çɽ¼¨ } }
¡¡¤½¤·¤Æ¡¢ºÇ¸å¤Ë¡¢¥¹¥³¥¢¤Î²Ã»»¤Èɽ¼¨¤òÄ´À°¤¹¤ë¿·¤¿¤ÊScoreManager¥¯¥é¥¹¤òºîÀ®¤·¤Þ¤¹¡£
using UnityEngine; public class ScoreManager : MonoBehaviour { // Score¥¯¥é¥¹¤ÈScoreDisplay¥¯¥é¥¹¤Ø¤Î»²¾È public Score score; public ScoreDisplay scoreDisplay; // ¥¹¥³¥¢¤ò²Ã»»¤·¡¢É½¼¨¤ò¹¹¿·¤¹¤ë¥á¥½¥Ã¥É public void AddScore(int amount) { score.AddScore(amount); scoreDisplay.DisplayScore(score.GetScore()); } }
¡¡¤³¤Î¤è¤¦¤Ë¡¢ScoreManager¥¯¥é¥¹¤¬Score¥¯¥é¥¹¤ÈScoreDisplay¥¯¥é¥¹¤ò´ÉÍý¤·¡¢¤½¤ì¤é¤òÏ¢·È¤µ¤»¤Þ¤¹¡£
¤³¤ì¤Ë¤è¤ê¡¢³Æ¥¯¥é¥¹¤Ï°ì¤Ä¤ÎÌò³ä¤ËÀìÇ°¤·¡¢Â¾¤Î¥¯¥é¥¹¤ÈÁ·ë¹ç¤Ë¤Ê¤ë¤³¤È¤¬²Äǽ¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¤³¤Î¤è¤¦¤ÊÀ߷פϡ¢¥³¡¼¥É¤Î²ÄÆÉÀ¡¢ÊݼéÀ¡¢ºÆÍøÍÑÀ¤ò¸þ¾å¤µ¤»¤ë¤Î¤ËÌòΩ¤Á¤Þ¤¹¡£
¡¡Ê¬³ä¸å¤Î¥¯¥é¥¹¤Ï¤½¤ì¤¾¤ì¤ÎÌò³ä¤ËÆò½¤·¤Æ¤¤¤ë¤¿¤á¡¢¥³¡¼¥É¤Î²ÄÆÉÀ¤ÈÊݼéÀ¤¬¸þ¾å¤·¤Þ¤¹¡£
¤½¤ì¤¾¤ì¤Î¥¯¥é¥¹¤¬¾®¤µ¤¯¤Ê¤Ã¤¿¤¿¤á¡¢ÆÃÄê¤Î¥á¥½¥Ã¥É¤äÊÑ¿ô¤ò¸«¤Ä¤±¤ä¤¹¤¯¤Ê¤ê¡¢¥Ç¥Ð¥Ã¥°¤âÍưפˤʤê¤Þ¤¹¡£
¡¡¤Þ¤¿¡¢³Æ¥¯¥é¥¹¤¬ÆÈΩ¤·¤Æ¤¤¤ë¤¿¤á¡¢É¬Íפʵ¡Ç½¤À¤±¤òºÆÍøÍѤ¹¤ë¤³¤È¤¬Íưפˤʤê¤Þ¤¹¡£
Î㤨¤Ð¡¢¥¹¥³¥¢¤Î²Ã»»¤À¤±¤¬É¬Íפʾì¹ç¤ÏScore¥¯¥é¥¹¤À¤±¤ò»ÈÍѤ·¡¢¥¹¥³¥¢¤Îɽ¼¨¤¬É¬Íפʾì¹ç¤ÏScoreDisplay¥¯¥é¥¹¤òÄɲ乤ë¤À¤±¤Ç¤¹¡£
¡¡¤³¤Î¤è¤¦¤Ë¡¢¥¯¥é¥¹¤Îʬ³ä¤Ï¡¢¤è¤êÎɤ¤¥³¡¼¥É¤ÎÀ߷פȳ«È¯¤ò¼Â¸½¤¹¤ë¤¿¤á¤Î½ÅÍפʼêË¡¤Ç¤¹¡£
¡¡¥×¥í¥°¥é¥à¤Ë¤ª¤¤¤Æ¤Ï¡¢Ê£¿ô¤Î¥¯¥é¥¹¤òÍøÍѤ¹¤ë¥±¡¼¥¹¤ÎÊý¤¬Â¿¤¯¤¢¤ê¤Þ¤¹¡£
¤Þ¤¿¥·¡¼¥óÁ«°Ü¤Î¤³¤È¤Ê¤É¤â¹Í¤¨¤¿À߷פò¹Ô¤¦¥±¡¼¥¹¤â¤¢¤ë¤¿¤á¡¢Ê£¿ô¤Î¥¯¥é¥¹¤¬¤É¤Î¤è¤¦¤Ë¤·¤Æ¤Ä¤Ê¤¬¤Ã¤Æ¤¤¤ë¤Î¤«¡¢ÇÄ°®¤¬Æñ¤·¤¤¤³¤È¤â¿¤¤¤Ç¤¹¡£
¡¡¤½¤¦¤¤¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢°ìÅÙ¡¢¤³¤¦¤¤¤Ã¤¿¥Ù¡¼¥·¥Ã¥¯¤Ê·Á¤Ç¡¢£±¤Ä¤Î¥¯¥é¥¹Æâ¤Ë¡¢¤ä¤ê¤¿¤¤½èÍý¤ò¤Þ¤È¤á¤Æ½ñ¤¤¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
¤½¤ì¤«¤é¡¢Ìò³ä¤ò¹Í¤¨¤¿¾å¤Ç¡¢¥¯¥é¥¹¤òʬ³ä¤·¤Æ¤¤¤¯¤³¤È¤Ç¡¢É¬ÍפʾðÊó¤äʬ³ä¤·¤¿Êý¤¬¤è¤¤¾ðÊ󤬸«¤¨¤Æ¤¤Þ¤¹¡£
¡¡½èÍý¤¬Ê£»¨¤Ë¤Ê¤ì¤Ð¤Ê¤ë¤Û¤É¡¢º®Íð¤òÀ¸¤¸¤ä¤¹¤¯¤Ê¤ê¤Þ¤¹¡£
¡¡¾ï¤Ë´ðËܤò¥¤¥á¡¼¥¸¤·¡¢´ðËܤËΩ¤ÁÌá¤Ã¤Æ¹Í¤¨¤ë¤è¤¦¤Ë¤·¤Æ¤ß¤ë¤³¤È¤Ç¡¢Ê¬³ä¤ÎÊýË¡¤ØÍý²ò¤¬¿¼¤Þ¤ê¤Þ¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯