how to move an object in unity 2d code example
Example 1: move gameobject in unity 2d
transform.position = new Vector3(transform.position.x + movespeed, transform.position.y);
Example 2: how to move a 2d character in unity
if (moveInput != 0)
{
velocity.x = Mathf.MoveTowards(velocity.x, speed * moveInput, walkAcceleration * Time.deltaTime);
}
else
{
velocity.x = Mathf.MoveTowards(velocity.x, 0, groundDeceleration * Time.deltaTime);
}