Home khkGames Classes Calendar Software Bibliothek Index Contact
Trail: moveWhenKeyPressed.cs

moveWhenKeyPressed.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class moveWhenKeyPressed : MonoBehaviour {
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKey(KeyCode.W)){
			//gameObject.transform.position=new Vector3(gameObject.transform.position.x+1,gameObject.transform.position.y,gameObject.transform.position.z);
			transform.Translate(Vector3.forward * Time.deltaTime);
		}
		
		if (Input.GetKey(KeyCode.S)){
			//gameObject.transform.position=new Vector3(gameObject.transform.position.x+1,gameObject.transform.position.y,gameObject.transform.position.z);
			transform.Translate(Vector3.back * Time.deltaTime);
		}
		if (Input.GetKey(KeyCode.A)){
			//gameObject.transform.position=new Vector3(gameObject.transform.position.x+1,gameObject.transform.position.y,gameObject.transform.position.z);
			transform.Translate(Vector3.left * Time.deltaTime);
		}
		if (Input.GetKey(KeyCode.D)){
			//gameObject.transform.position=new Vector3(gameObject.transform.position.x+1,gameObject.transform.position.y,gameObject.transform.position.z);
			transform.Translate(Vector3.right * Time.deltaTime);
		}
	}
 }