unity 键盘控制移动

using UnityEngine;
using System.Collections;
public class textinput : MonoBehaviour {
 public float speed;
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
//	 if (Input.GetKey (KeyCode.Space)) {
//
//	 }
//	 else if(Input.GetKeyDown(KeyCode.Space)){
//
//	 }
//	 else if(Input.GetKeyUp(KeyCode.Space)){
//
//	 }
//	 if(Input.GetMouseButton(0)){
//
//	 }
//	 else if(Input.GetMouseButtonDown(1)){
//
//	 }
//	 else if(Input.GetMouseButtonUp(2)){
//
//	 }
  if(Input.GetKey(KeyCode.W)){
   transform.position=new Vector3(transform.position.x,transform.position.y+speed,transform.position.z);
  }
  else if(Input.GetKey(KeyCode.S)){
   transform.position=new Vector3(transform.position.x,transform.position.y-speed,transform.position.z);
  }
   if(Input.GetKey(KeyCode.A)){
   transform.position=new Vector3(transform.position.x-speed,transform.position.y,transform.position.z);
  }
  else if(Input.GetKey(KeyCode.D)){
   transform.position=new Vector3(transform.position.x+speed,transform.position.y,transform.position.z);
  }
 }
}


 
  
 
 

你可能感兴趣的:(Unity3D,常用)