Unity¤Ë´ØÏ¢¤¹¤ëµ­»ö¤Ç¤¹

¡¡¶ñÂÎŪ¤Ê¥²¡¼¥àÆâ¤Î½èÍý¤òÎã¤Ë¡¢switchʸ¤Èifʸ¤Î»È¤¤Ê¬¤±¤ò²òÀ⤷¤Þ¤¹¡£

¡¡Î¾Êý¤Îµ­½Ò¤Ë¤Ä¤¤¤Æ·ÇºÜ¤·¤Þ¤¹¤¬¡¢¤è¤êŬ¤·¤Æ¤¤¤ëµ­Ë¡¤òÀè¤ËÄ󼨤·¤Þ¤¹¡£



£±¡¥¥­¥ã¥é¥¯¥¿¡¼¤Î¾õÂ֤˱þ¤¸¤¿¥¢¥Ë¥á¡¼¥·¥ç¥ó¤ÎÀÚ¤êÂؤ¨


¡¡¥²¡¼¥àÆâ¤Î¥­¥ã¥é¥¯¥¿¡¼¤¬¡¢Áö¤Ã¤Æ¤¤¤ë¾õÂÖ¡¢¥¸¥ã¥ó¥×¤·¤Æ¤¤¤ë¾õÂÖ¡¢¹¶·â¤·¤Æ¤¤¤ë¾õÂ֤Ȥ¤¤Ã¤¿Ê£¿ô¤Î¾õÂÖ¤ò»ý¤Ã¤Æ¤¤¤ë¤È¤·¤Þ¤¹¡£

¡¡¤³¤ì¤é¤Î¾õÂ֤˱þ¤¸¤ÆŬÀڤʥ¢¥Ë¥á¡¼¥·¥ç¥ó¤òɽ¼¨¤·¤¿¤¤¤È¤­¡¢enum¤Èswitchʸ¤ò»È¤¦¤È¥³¡¼¥É¤¬¤­¤ì¤¤¤Ë¤Þ¤È¤Þ¤ê¤Þ¤¹¡£


¡ãswitch ʸ¤Î¾ì¹ç¡ä


// enum¤Ç¥­¥ã¥é¥¯¥¿¡¼¤Î¾õÂÖ¤òÄêµÁ
public enum CharacterState {
    Running,
    Jumping,
    Attacking
}

// ¥­¥ã¥é¥¯¥¿¡¼¤Î¾õÂÖ
CharacterState state = CharacterState.Running;

// switchʸ¤ò»È¤Ã¤Æ¡¢¾õÂ֤˱þ¤¸¤¿¥¢¥Ë¥á¡¼¥·¥ç¥ó¤òºÆÀ¸
switch (state) {
    case CharacterState.Running:
        // Running¤Î¥¢¥Ë¥á¡¼¥·¥ç¥ó¤òºÆÀ¸
        break;
    case CharacterState.Jumping:
        // Jumping¤Î¥¢¥Ë¥á¡¼¥·¥ç¥ó¤òºÆÀ¸
        break;
    case CharacterState.Attacking:
        // Attacking¤Î¥¢¥Ë¥á¡¼¥·¥ç¥ó¤òºÆÀ¸
        break;
    default:
        // ̤ÄêµÁ¤Î¾õÂ֤ξì¹ç¤Î½èÍý
        break;
}


¡ãif ʸ¤Î¾ì¹ç¡ä


¡¡°Ê²¼¤Î¤è¤¦¤Ëifʸ¤ò»ÈÍѤ·¤Æ¤âƱ¤¸¤è¤¦¤Ë½èÍý¤Ç¤­¤Þ¤¹¤¬¡¢switchʸ¤ò»È¤¦Êý¤¬²ÄÆÉÀ­¤¬¹â¤¤¤Ç¤¹¡£
Æäˡ¢¾õÂÖ¤¬¹¹¤ËÁý¤¨¤ë¾ì¹ç¡¢ifʸ¤Ç¤ÏÊ£»¨¤µ¤¬Áý¤·¤Æ¤·¤Þ¤¤¤Þ¤¹¡£

CharacterState state = CharacterState.Running;

// ifʸ¤Ç½ñ¤­Ä¾¤¹
if (state == CharacterState.Running) {
    // Running¤Î¥¢¥Ë¥á¡¼¥·¥ç¥ó¤òºÆÀ¸
} else if (state == CharacterState.Jumping) {
    // Jumping¤Î¥¢¥Ë¥á¡¼¥·¥ç¥ó¤òºÆÀ¸
} else if (state == CharacterState.Attacking) {
    // Attacking¤Î¥¢¥Ë¥á¡¼¥·¥ç¥ó¤òºÆÀ¸
} else {
    // ̤ÄêµÁ¤Î¾õÂ֤ξì¹ç¤Î½èÍý
}



£²¡¥Å¨¥­¥ã¥é¥¯¥¿¡¼¤ÎAI¹ÔÆ°


¡¡Å¨¥­¥ã¥é¥¯¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤Îµ÷Î¥¤Ë±þ¤¸¤Æ¹ÔÆ°¤òÊѤ¨¤ë¾ì¹ç¡¢ifʸ¤¬ÊØÍø¤Ç¤¹¡£
µ÷Î¥¤¬10m°Ê²¼¤Ê¤é¹¶·â¡¢20m°Ê²¼¤Ê¤éÀܶᡢ¤½¤ì°Ê¾å¤Ê¤éÂÔµ¡¤È¤¤¤Ã¤¿¶ñÂÎŪ¤ÊÈϰϤ˴ð¤Å¤¤¤¿¾ò·ï¤òÀßÄê¤Ç¤­¤Þ¤¹¡£


¡ãif ʸ¤Î¾ì¹ç¡ä

float distance = // ¥×¥ì¥¤¥ä¡¼¤È¤Îµ÷Î¥

// ifʸ¤ò»È¤Ã¤Æ¡¢µ÷Î¥¤Ë±þ¤¸¤¿¹ÔÆ°¤òÁªÂò
if (distance <= 10) {
    // ¹¶·â¤¹¤ë
} else if (distance <= 20) {
    // À᤹ܶ¤ë
} else {
    // ÂÔµ¡¤¹¤ë
}


¡ãswitch ʸ¤Î¾ì¹ç¡ä


¡¡°Ê²¼¤Î¤è¤¦¤Ëswitchʸ¤ò»ÈÍѤ·¤Æ¤â½èÍý¤Ï²Äǽ¤Ç¤¹¤¬¡¢²ÄÆÉÀ­¤â°­¤¯¡¢ÈϰϤ˴ð¤Å¤¯¾ò·ïȽÃǤ¬Æñ¤·¤¯¤Ê¤ë¤¿¤á¡¢¤³¤Î¾ì¹ç¤Ïifʸ¤ÎÊý¤¬Å¬¤·¤Æ¤¤¤Þ¤¹¡£

float distance = // ¥×¥ì¥¤¥ä¡¼¤È¤Îµ÷Î¥

// switchʸ¤Ç½ñ¤­Ä¾¤¹¡ÊÈó¿ä¾©¡Ë
switch (distance) {
    case var d when d <= 10:
        // ¹¶·â¤¹¤ë
        break;
    case var d when d <= 20:
        // À᤹ܶ¤ë
        break;
    default:
        // ÂÔµ¡¤¹¤ë
        break;
}


£³¡¥¥¤¥Ù¥ó¥ÈȯÀ¸»þ¤Î½èÍý


¡¡¥²¡¼¥àÆâ¤ÎÆÃÄê¤Î¥¤¥Ù¥ó¥È¡Ê¤¿¤È¤¨¤Ð¡¢¥×¥ì¥¤¥ä¡¼¤¬ÊõÈ¢¤ò³«¤±¤ë¡¢Å¨¤òÅݤ¹¤Ê¤É¡Ë¤¬È¯À¸¤·¤¿¤È¤­¤Ë¡¢¤½¤ì¤¾¤ì°Û¤Ê¤ë½èÍý¤ò¹Ô¤¤¤¿¤¤¾ì¹ç¡¢switchʸ¤¬Å¬¤·¤Æ¤¤¤Þ¤¹¡£

¡¡ÀßÄꤵ¤ì¤Æ¤¤¤ëÈϰϤ¬»öÁ°¤Ë·è¤Þ¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢¤ä¤Ï¤ê¡¢enum ¤È¤ÎÁȤ߹ç¤ï¤»¤¬¸ú²ÌŪ¤Ç¤¹¡£


¡ãswitch ʸ¤Î¾ì¹ç¡ä


// enum¤Ç¥¤¥Ù¥ó¥È¤Î¼ïÎà¤òÄêµÁ
public enum GameEvent {
    OpenChest,
    DefeatEnemy,
    ReachGoal
}

// ¥²¡¼¥à¥¤¥Ù¥ó¥È
GameEvent gameEvent = GameEvent.OpenChest;

// switchʸ¤ò»È¤Ã¤Æ¡¢¥¤¥Ù¥ó¥È¤Ë±þ¤¸¤¿½èÍý¤ò¼Â¹Ô
switch (gameEvent) {
    case GameEvent.OpenChest:
        // ÊõÈ¢¤ò³«¤±¤ë½èÍý¡Ê¥¢¥¤¥Æ¥à¤ò³ÍÆÀ¤¹¤ëÅù¡Ë
        break;
    case GameEvent.DefeatEnemy:
        // Ũ¤òÅݤ¹½èÍý¡Ê·Ð¸³ÃͤòÆÀ¤ëÅù¡Ë
        break;
    case GameEvent.ReachGoal:
        // ¥´¡¼¥ë¤ËÅþ㤷¤¿½èÍý¡Ê¥ì¥Ù¥ë¥¯¥ê¥¢Åù¡Ë
        break;
    default:
        // ̤ÄêµÁ¤Î¥¤¥Ù¥ó¥È¤Î¾ì¹ç¤Î½èÍý
        break;
}


¡ãif ʸ¤Î¾ì¹ç¡ä


¡¡°Ê²¼¤Î¤è¤¦¤Ëifʸ¤ò»ÈÍѤ·¤Æ¤â½èÍý¤Ç¤­¤Þ¤¹¤¬¡¢switchʸ¤ÎÊý¤¬åºÎï¤Ë¤Þ¤È¤Þ¤ê¡¢¤Þ¤¿ÃͤÎÈϰϤ¬¸ÂÄꤵ¤ì¤ë¤¿¤á¡¢Æɤߤ䤹¤µ¤È¥Ð¥°¤ÎȯÀ¸¤òËɤ°ÅÀ¤ÇÍ¥¤ì¤Æ¤¤¤Þ¤¹¡£

GameEvent gameEvent = GameEvent.OpenChest;

// ifʸ¤Ç½ñ¤­Ä¾¤¹
if (gameEvent == GameEvent.OpenChest) {
    // ÊõÈ¢¤ò³«¤±¤ë½èÍý¡Ê¥¢¥¤¥Æ¥à¤ò³ÍÆÀ¤¹¤ëÅù¡Ë
} else if (gameEvent == GameEvent.DefeatEnemy) {
    // Ũ¤òÅݤ¹½èÍý¡Ê·Ð¸³ÃͤòÆÀ¤ëÅù¡Ë
} else if (gameEvent == GameEvent.ReachGoal) {
    // ¥´¡¼¥ë¤ËÅþ㤷¤¿½èÍý¡Ê¥ì¥Ù¥ë¥¯¥ê¥¢Åù¡Ë
} else {
    // ̤ÄêµÁ¤Î¥¤¥Ù¥ó¥È¤Î¾ì¹ç¤Î½èÍý
}


£´¡¥switchʸ¤Èifʸ¤Î»È¤¤Ê¬¤±¤Î¥Ý¥¤¥ó¥È


¡¡¤³¤ì¤é¤Î¥±¡¼¥¹¤è¤¦¤Ë¡¢switchʸ¤Èifʸ¤Ï¤½¤ì¤¾¤ì°Û¤Ê¤ë¾õ¶·¤Ë¤ª¤¤¤ÆÍ¥¤ì¤¿Æɤߤ䤹¤µ¤È¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤òÄ󶡤¹¤ë¤³¤È¤¬ÌÜŪ¤Ç¤¹¡£

¡¡Àè¤Û¤É¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤òǰƬ¤ËÃÖ¤¤¤Æ¡¢¤½¤ì¤¾¤ì¤ÎÆÃħ¤ò¸«Ä¾¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡£



¡¡switchʸ¤Ï¡¢¤¢¤ëÊÑ¿ô¤¬ÆÃÄê¤ÎÃͤò»ý¤Ã¤Æ¤¤¤ë¤«¤É¤¦¤«¤ò·«¤êÊÖ¤·³Îǧ¤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤ËÊØÍø¤Ç¤¹¡£
Æäˡ¢¤³¤ÎÊÑ¿ô¤ÎÃͤ¬¤¢¤é¤«¤¸¤á¸ÂÄꤵ¤ì¤¿ÈÏ°ÏÆâ(¥»¥Ã¥È)¤Ë¤¢¤ë¤³¤È¤¬Ê¬¤«¤Ã¤Æ¤¤¤ë¾ì¹ç¡ÊÎ㡧¥­¥ã¥é¥¯¥¿¡¼¤Î¾õÂ֤䥲¡¼¥à¥¤¥Ù¥ó¥È¤Ê¤É¡Ë¤Ë¤Ï¡¢enum¤È°ì½ï¤Ë»È¤¦¤ÈÈó¾ï¤Ë¸ú²ÌŪ¤Ç¤¹¡£

¡¡¤³¤Î¥»¥Ã¥È¤¬¤¢¤é¤«¤¸¤áÃΤé¤ì¤Æ¤¤¤Æ¡¢¤½¤ì¤é¤ÎÁªÂò»è¤¬Áê¸ß¤ËÇÓ¾Ū¤Ç¤¢¤ë¾ì¹ç¡¢switchʸ¤Ï¥³¡¼¥É¤ò¤­¤ì¤¤¤ËÊݤĤΤËÌòΩ¤Á¤Þ¤¹¡£¤½¤ì¤Ï¤Þ¤¿¡¢¤¢¤ëÊÑ¿ô¤¬¼è¤ê¤¦¤ëÃͤò¸«¤Ä¤±¤ä¤¹¤¯¤¹¤ë¤¿¤á¡¢¥Ð¥°¤ò¸«¤Ä¤±¤ë¤Î¤ËÌòΩ¤Ä²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£



¡¡°ìÊý¡¢ifʸ¤Ï¡¢°ìÏ¢¤Î¾ò·ï¤ò½çÈ֤˳Îǧ¤·¡¢ºÇ½é¤Ë¿¿¤È¤Ê¤ë¾ò·ï¤ËÂбþ¤¹¤ë½èÍý¤ò¼Â¹Ô¤·¤¿¤¤¾ì¹ç¤ËÊØÍø¤Ç¤¹¡£
ÊÑ¿ô¤¬ÆÃÄê¤ÎÈÏ°ÏÆâ¤Ë¤¢¤ë¤«¤É¤¦¤«¤ò³Îǧ¤¹¤ë¾ì¹ç¡ÊÎ㡧Ũ¥­¥ã¥é¥¯¥¿¡¼¤ÎAI¹ÔÆ°¤Ê¤É¡Ë¤Ë¤Ï¡¢ifʸ¤¬¼«Á³¤Ë¥Õ¥£¥Ã¥È¤·¤Þ¤¹¡£

¡¡Æäˡ¢Ï¢Â³Åª¤ÊÈϰϤޤ¿¤Ï¾ò·ï¤¬½ÅÊ£¤¹¤ë²ÄǽÀ­¤¬¤¢¤ë¾ì¹ç¤ËÍ­ÍѤǤ¹¡£
°Û¤Ê¤ëÈϰϤ˸٤ë¾ò·ï¤ò°·¤¦¤³¤È¤¬²Äǽ¤Ç¤¢¤ê¡¢¤½¤ì¤¬switchʸ¤Î¾ì¹ç¤Ë¤Ïµ­½Ò¤¬º¤Æñ¤Ë¤Ê¤ê¤Þ¤¹¡£


£µ¡¥¤Þ¤È¤á


¡¡switchʸ¤Èifʸ¤Î»È¤¤Ê¬¤±Êý¤Î¼ÂÁõÎã¤òÄ󼨤·¤Þ¤·¤¿¡£
¤½¤ì¤¾¤ì¤Î¥Ý¥¤¥ó¥È¤òÍý²ò¤¤¤¿¤À¤±¤ì¤Ð¹¬¤¤¤Ç¤¹¡£

¡¡ºÇ½ªÅª¤Ë¤Ï¡¢»È¤¤¤ä¤¹¤µ¡¢¥³¡¼¥É¤Î²ÄÆÉÀ­¡¢¤½¤·¤Æ¤¢¤Ê¤¿¤¬¤É¤ÎÄøÅÙ¤ÎÀºÅ٤Ǿò·ï¤òÀ©¸æ¤·¤¿¤¤¤«¤Ë¤è¤ê¤Þ¤¹¡£
ξ¼Ô¤Î°ã¤¤¤òÍý²ò¤·¡¢¼«¿È¤Î¥Ë¡¼¥º¤ËºÇŬ¤ÊÁªÂò¤ò¹Ô¤¦¤³¤È¤¬½ÅÍפǤ¹¡£

¡¡¤É¤Á¤é¤ÎÊý¤¬Å¬¤·¤Æ¤¤¤ë¤«¤Ï¡¢¼ÂºÝ¤Ë¼«Ê¬¤ÇξÊý¤Î¥±¡¼¥¹¤ò½ñ¤¤¤Æ¤ß¤Ê¤¬¤é»È¤¤Êý¤ò½¬ÆÀ¤·¤Æ¤¤¤¯¤³¤È¤ò¤ª´«¤á¤·¤Þ¤¹¡£

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

Menu


´ðÁÃ

µ»½Ñ/Ãμ±(¼ÂÁõÎã)

3D¥¢¥¯¥·¥ç¥ó¥²¡¼¥à

2D¤ª¤Ï¤¸¤­¥²¡¼¥à(ȯŸÊÔ)

2D¶¯À©²£¥¹¥¯¥í¡¼¥ë¥¢¥¯¥·¥ç¥ó(ȯŸÊÔ)

2D¥¿¥Ã¥×¥·¥å¡¼¥Æ¥£¥ó¥°(³ÈÄ¥ÊÔ)

¥ì¡¼¥¹¥²¡¼¥à(È´¿è)

2DÊüÃÖ¥²¡¼¥à(ȯŸÊÔ)

3D¥ì¡¼¥ë¥¬¥ó¥·¥å¡¼¥Æ¥£¥ó¥°(±þÍÑÊÔ)

3Dæ½Ð¥²¡¼¥à(È´¿è)

2D¥ê¥¢¥ë¥¿¥¤¥à¥¹¥È¥é¥Æ¥¸¡¼

3D¥¿¥Ã¥×¥¢¥¯¥·¥ç¥ó(NavMeshAgent »ÈÍÑ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥«¥¨¥ë¤Î°Ù¤Ë¡Á¡¢¥Ü¥³¥¹¥«¥¦¥©¡¼¥ºÉ÷)

VideoPlayer ¥¤¥Ù¥ó¥ÈϢư¤Î¼ÂÁõÎã

VideoPlayer ¥ê¥¹¥ÈÆ⤫¤é¥à¡¼¥Ó¡¼ºÆÀ¸¤Î¼ÂÁõÎã(ȯŸ)

AR ²èÁüÉÕ¤­¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®¤Î¼ÂÁõÎã

AR ¥ê¥¹¥ÈÆ⤫¤éÀ¸À®¤Î¼ÂÁõÎã(ȯŸ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥µ¥Ð¥¤¥Ð¡¼É÷)

private



¤³¤Î¥µ¥¤¥ÈÆâ¤ÎºîÉʤϥæ¥Ë¥Æ¥£¤Á¤ã¤ó¥é¥¤¥»¥ó¥¹¾ò¹à¤Î¸µ¤ËÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹