LoginSignup
1
1

More than 3 years have passed since last update.

C#:列挙型の解説

Posted at
Sample.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// 列挙型とは?
// * コードを読みやすくするためのもの(可読性をあげる)
// * 制限の中から選択可能にするもの

public class Sample : MonoBehaviour
{
    enum DIRECTION {
        UP,
        DOWN,
        RIGHT,
        LEFT,
    }

    DIRECTION direction = DIRECTION.DOWN;
    int directionInt = 0; // 0:上

    void Start()
    {

        if (directionInt == 0)
        {
            Debug.Log("下");
        }
        else if(directionInt == 1)
        {
            Debug.Log("上");
        }

        switch (direction)
        {
            case DIRECTION.DOWN:
                Debug.Log("下");
                break;
            case DIRECTION.UP:
                Debug.Log("下");
                break;
            case DIRECTION.RIGHT:
                Debug.Log("下");
                break;
            case DIRECTION.LEFT:
                Debug.Log("下");
                break;
        }

        /*
        if (direction == DIRECTION.Down)
        {
            Debug.Log("下");
        }
        else if (direction == DIRECTION.Up)
        {
            Debug.Log("上");

        }
        else if (direction == DIRECTION.RIGHT)
        {
            Debug.Log("右");

        }
        else if (direction == DIRECTION.LEFT)
        {
            Debug.Log("左");
        }
        */

    }
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1