Answers for "how to move object with keyboard in unity 3D"

C#
0

how to move object in unity with keyboar

if (Input.GetKeyDown(KeyCode.LeftArrow))
{
    Vector3 position = this.transform.position;
    position.x--;
    this.transform.position = position;
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
    Vector3 position = this.transform.position;
    position.x++;
    this.transform.position = position;
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
    Vector3 position = this.transform.position;
    position.y++;
    this.transform.position = position;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
    Vector3 position = this.transform.position;
    position.y--;
    this.transform.position = position;
}
Posted by: Guest on October-06-2020
0

how to move object with keyboard in unity 3D

public class realguymoves : MonoBehaviour //the class of object
{
    //movement
    float speed;

    float horizontal;
    float vertical;
    Vector3 moveDirecion;
    float drag;



    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxisRaw("Horizontal"); //getting the horizontal axis of the object
        vertical = Input.GetAxisRaw("Vertical"); //getting the vectical axis of the object

        moveDirecion = transform.forward * vertical + transform.right * horizontal;
    }
Posted by: Guest on August-04-2021

Code answers related to "how to move object with keyboard in unity 3D"

C# Answers by Framework

Browse Popular Code Answers by Language