using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cubemove : MonoBehaviour
{
//第一种移动方式
public int speed = 5;
public float H;
public float V;
// Update is called once per frame
void Update()
{
H = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
V = Input.GetAxis("Vertical") * Time.deltaTime * speed;
this.gameObject.transform.Translate(H, 0, V);
}
//第二种移动方式
public GameObject player;
void Update()
{
if (Input.GetKey(KeyCode.W))
{
player.transform.Translate(Vector3.forward * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
player.transform.Translate(Vector3.back * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A))
{
player.transform.Translate(Vector3.left * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D))
{
player.transform.Translate(Vector3.right * Time.deltaTime);
}
}
}