zoukankan      html  css  js  c++  java
  • Unity官方案例精讲_2015_优化

    1.将公共变量从Inspector视图中隐藏:    [HideInInspector]

        [HideInInspector]
        public GameObject player;

    2.限定Inspector面板上属性值的范围:    [Range(min,max)]

        [Range(0f,255f)]
        public int num;

    3.在C++中参数的传递方式有:传值,传址,传引用,在C#中只存在在传值,传引用,其中传引用可由关键字ref和out完成,两者之间的区别在于若用ref方式来传递参数,则该实际参数必须先初始化,而out方式则不需要初始化,out参数也称为输出参数。

        void Start () {
            string str1;
            OutFun(out str1);//参数可以不用初始化
            string str = "hello word";
            RefFun(ref str);//参数必须初始化public void OutFun(out string str) {
                str = "我是OUT参数";
            }
            public void RefFun(ref string str) {
                str = "我是ref参数";
            }
    }

    4.协程(Coroutine):中断当前执行的代码,直到终端指令结束接着执行下面代码。

     5.在Update函数中,需要通过Time.deltaTime来抵消帧率带来的影响,但在FixedUpdate函数中,由于其更新帧频率固定,所以不需要使用Time.deltaTime。

    控制游戏对象移动的方法:

        void FixedUpdate() {
            float h = Input.GetAxis("Horizontal");
            float v = Input.GetAxis("Vertical");
            //方法一
            //Vector3 dir = new Vector3(h, 0, v);
            //GetComponent<Rigidbody>().velocity = dir;
    
            //方法二
            //GetComponent<Rigidbody>().AddForce(new Vector3(h, 0, v));
        }
    
        void Update () {
            float h = Input.GetAxis("Horizontal");
            float v = Input.GetAxis("Vertical");
            //方法三
            //transform.Translate(new Vector3(h, 0, v));
        }
    PlayerMove
  • 相关阅读:
    类中以双下划线開始的方法
    Dynamics CRM2016 新功能之从CRM APP中导出数据至EXCEL
    敏捷项目管理实践
    Hibernate环境搭建
    ubuntu12.04更新软件源时出现校验和不符
    修炼你自己
    http自己定义超时检測方法、主动抛出异常
    sql server 2008安装图解
    Ural 1353 Milliard Vasya&#39;s Function(DP)
    待字闺中之构造最大数分析
  • 原文地址:https://www.cnblogs.com/shirln/p/9289017.html
Copyright © 2011-2022 走看看