unity中控制物体的移动,和旋转

来源:互联网 发布:百战天下数据 编辑:程序博客网 时间:2024/06/09 19:46


   unity中角色的控制

     unity菜单栏中的edit --> project setting --> input , 这个时候我们可以看到右边的虚拟轴的集合, 



   


  这个时候,你可以设置按键灯一些东西,  在空间坐标上, 正方向用input.GetAxis(""....""); 得到的是1, 负方向得到的是-1, 我们可以通过自己设定速率,来进行移动物体,

,,



  using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class control : MonoBehaviour {


    private float speed = 10;


// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {


        float ho =  Input.GetAxis("Horizontal")*speed*Time.deltaTime;


        float ve = Input.GetAxis("Vertical") * speed * Time.deltaTime;


        //GetComponent<Transform>().Rotate(0, ho, 0);      rotate可以使物体旋转
        GetComponent<Transform>().Translate(ho, 0, ve);        Translate可以使物体移动 


}
}

  


0 0