badgz.blogg.se

Unity 2d movement script download
Unity 2d movement script download













unity 2d movement script download

This approach is by no means perfect, or even good. If you want to be sure you understand how this works, try adding vertical movement in yourself, the code is very similar to what I've written here (even if you don't need vertical movement its good for practice).

unity 2d movement script download

Transform.position = new Vector2( - (speed * ltaTime), ) Transform.localScale = new Vector3(-1, 1, 1) Transform.position = new Vector2( + (speed * ltaTime), ) Įlse if (Input.GetAxis("Horizontal") < -0.01f) You want to edit transform.position of the GameObject (the location of your object).Īssuming that this is a 2D project, for basic horizontal movement you can do the following: using System.Collections

unity 2d movement script download

Right now, your code is just changing what direction the player faces since you're editing transform.localScale (how big the object is / what direction your object faces).















Unity 2d movement script download