zoukankan      html  css  js  c++  java
  • Unity3D 物体按键WASD转头并移动

             // 按W键,向上移动
            if (Input.GetKey(KeyCode.W))
            {
                Vector3 e_rot = transform.eulerAngles;
                e_rot.x = -90;
                e_rot.y = 0;
                e_rot.z = 0;
                transform.eulerAngles = e_rot;
                transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.Self);
            }
            // 按S键,向下移动
            else if (Input.GetKey(KeyCode.S))
            {
                Vector3 eulerAngles = transform.eulerAngles;
                eulerAngles.x = 90;
                eulerAngles.y = 0;
                eulerAngles.z = 180;
                transform.eulerAngles = eulerAngles;
                transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.Self);
            }
            // 按A键,向左移动
            else if (Input.GetKey(KeyCode.A))
            {
                Vector3 eulerAngles = transform.eulerAngles;
                eulerAngles.x = 0;
                eulerAngles.y = -90;
                eulerAngles.z = 90;
                transform.eulerAngles = eulerAngles;
                transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.Self);
            }
            // 按D键,向右移动
            else if (Input.GetKey(KeyCode.D))
            {
                Vector3 eulerAngles = transform.eulerAngles;
                eulerAngles.x = 0;
                eulerAngles.y = 90;
                eulerAngles.z = -90;
                transform.eulerAngles = eulerAngles;
                transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.Self);
            }
    

      

  • 相关阅读:
    [CodeForces
    [CodeChef]RIN(最小割)
    [Bzoj3894]文理分科(最小割)
    [Poj3469]Dual Core CPU(最小割)
    MySQL- 锁(3)
    MySQL- 锁(1)
    MySQL- 锁(2)
    MySQL-中文全文检索
    Solr
    多线程编程-之并发编程:同步容器
  • 原文地址:https://www.cnblogs.com/yuwuji/p/7979468.html
Copyright © 2011-2022 走看看