关于物体的位移
unity 中 所有的一切都是通过添加或者删除组件来进行最基本的操作;
脚本就是用来操作的手段;
位移;
using UnityEngine;
using System.Collections;
public class playermove : MonoBehaviour {
public GameObject play;
// Use this for initialization
float a;
float b;
void Start () {
play = GameObject.FindGameObjectWithTag("play");
}
// Update is called once per frame
void Update () {
//if (Input.GetKey(KeyCode.A))
//{
// play.transform.Translate(-10*Time.deltaTime,0,0);
//}
//if (Input.GetKey(KeyCode.D))
//{
// play.transform.Translate(10*Time.deltaTime,0,0);
//}
//if (Input.GetKey(KeyCode.W))
//{
// play.transform.Translate(0,-10*Time.deltaTime,0);
//}
//if (Input.GetKey(KeyCode.S))
//{
// play.transform.Translate(0,10*Time.deltaTime,0);
//}
a = Input.GetAxis("Vertical");
b = Input.GetAxis("Horizontal");
play.transform.Translate(0, a * Time.deltaTime*10, 0);
play.transform.Translate(b * Time.deltaTime*10, 0, 0);
}
}
这上面的代码 有两种控制方式 看个人喜好
我建议使用虚拟轴 这样代码比较简洁