Answers for "unity 2d how to move square with keyboard"

C#
0

unity 2d how to move square with keyboard

public float speed;
 
    void Update ()
    {
        // GetAxisRaw is unsmoothed input -1, 0, 1
        float v = Input.GetAxisRaw("Vertical");
        float h = Input.GetAxisRaw("Horizontal");
 
        // normalize so going diagonally doesn't speed things up
        Vector3 direction = new Vector3(h, v, 0f).normalized;
 
        // translate
        transform.Translate(direction * speed * Time.deltaTime);
    }
Posted by: Guest on December-27-2020

Code answers related to "unity 2d how to move square with keyboard"

C# Answers by Framework

Browse Popular Code Answers by Language