Tuesday, 15 September 2015

move a object with keyboard up,down,left,right unity c#

using UnityEngine;
using System.Collections;

public class move : MonoBehaviour {

    private float speed = 2.0f;
    void Update () {
        
        if (Input.GetKey(KeyCode.RightArrow)){
            transform.position += Vector3.right * speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.LeftArrow)){
            transform.position += Vector3.left * speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.UpArrow)){
            transform.position += Vector3.forward * speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.DownArrow)){
            transform.position += Vector3.back * speed * Time.deltaTime;
        }
    }
}



No comments:

Post a Comment