using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class yidong : MonoBehaviour {
private float x;
private float y;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
//获取水平轴
x = Input.GetAxis(“Horizontal”);
//获取垂直轴
y = Input.GetAxis(“Vertical”);
//控制移动
transform.Translate(new Vector3(y, 0, x)*0.3f);
}
}
public GameObject obj;
public Vector3 newposx;
public Vector3 newposz;
private void Start()
{
newposz = new Vector3(0, 0, 0.1f);
newposx = new Vector3(0.1f, 0, 0);
}
public void Update()
{
if (Input.GetKey(KeyCode.A))
{
this.gameObject.transform.position -= newposx;
}
else if (Input.GetKey(KeyCode.D))
{
this.gameObject.transform.position += newposx;
}
else if (Input.GetKey(KeyCode.W))
{
this.gameObject.transform.position += newposz;
}
else if (Input.GetKey(KeyCode.S))
{
this.gameObject.transform.position -= newposz;
}
}