Unity学习 180802 枚举类控制

用到的标记

[RequireComponent(typeof(Rigidbody))] //需要属性Rigidbody

用到的属性关键字

public enum MoveDirection {idle,right,up,forward};//枚举类型 选择移动的方向

public MoveDirection direct;//声明枚举类

public Rigidbody rig;

执行


void FixedUpdate () {

                if(direct==MoveDirection.idle){

      rig.velocity = Vector3.zero;

        }

        if(direct==MoveDirection.right){

      rig.velocity = transform.right *1;

        }

        if(direct==MoveDirection.forward){

            rig.velocity = transform.forward *1;

        }

        if(direct==MoveDirection.up){

            rig.velocity = transform.up *1;

        }

//不能直接使用Rigidbody.Velocity会报错

// 'Component.rigidbody' is obsolete: 'Property rigidbody has been deprecated. Use GetComponent() instead.

    }

你可能感兴趣的:(Unity学习 180802 枚举类控制)