Created
July 27, 2021 07:24
-
-
Save Aphellirus/eef5f6f897eda753847a4550ee08ae7e to your computer and use it in GitHub Desktop.
Controling an Object's movement through Keyboard input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class objectControl : MonoBehaviour | |
{ | |
public float speed = 3.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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment