Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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;
    }
 
PREVIOUS NEXT
Tagged: #move #object #keyboard #unity
ADD COMMENT
Topic
Name
1+5 =