您的位置:首页 > 移动开发 > Unity3D

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

2017-05-06 15:50 609 查看
   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可以使物体移动 

}

}

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: