Unity3D:活用int类型表示状态

直接上代码

using System;

namespace Arithmetic
{
    class Program
    {
        public enum State
        {
            Idle,
            Walk,
            Run,
            Jump,
        }
        static void Main(string[] args)
        {
            int state = 1 << (int)State.Idle;
            Console.WriteLine("当前是否又跑又跳:" + CheckState(state));
            state = 1 << (int)(State.Run | State.Jump);
            Console.WriteLine("当前是否又跑又跳:" + CheckState(state));
            Console.Read();
        }
        //检查当前的状态是否又跑又跳
        private static bool CheckState(int state)
        {
            return state == 1 << (int)(State.Run | State.Jump);
        }
    }
}

你可能感兴趣的:(Unity3D:初级教程,c#)