unity基础,控制游戏目标

来源:互联网 发布:linux编译环境搭建 编辑:程序博客网 时间:2024/05/16 17:42

1.通过键盘按键控制事件:

        public KeyCode keyCode = KeyCode.Space;

        if (Input.GetKeyDown(keyCode)){  };

2.通过键盘按键控制目标移动:

     public float speed = 5;  //水平速度     public float angularSpeed = 30;//旋转角速度     private Rigidbody rigidbody= GetComponent<Rigidbody>();     float v = Input.GetAxis("VerticalPlayer");     float h = Input.GetAxis("HorizontalPlayer");     rigidbody.velocity = transform.forward * v * speed;     rigidbody.angularVelocity = transform.up * h *


3.点击屏幕控制

if (Input.GetMouseButton(0))      {                Rigidbody rigidbody = this.GetComponent<Rigidbody>();                rigidbody.velocity = new Vector3(x,y,z);      }