Unity fundamentals / 06

Let's move an object

Read Unity's horizontal input axis and move the practice sprite with a configurable speed.

On this page

Today, we will finally move our object. Open the Move script used in the previous lesson and enter the following code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{
    Rigidbody2D rigid;
    public float Movesp;

    Vector3 moove;
    // Start is called before the first frame update
    void Start()
    {
        rigid = gameObject.GetComponent<Rigidbody2D> ();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        PMove();
    }
    
    void PMove()
    {
         
        Vector3 movevelocity = Vector3.zero;

        if (Input.GetAxisRaw("Horizontal") < 0)
        {
            movevelocity = Vector3.left;
        }
        else if (Input.GetAxisRaw("Horizontal") > 0)
        {
            movevelocity = Vector3.right;
        }
        transform.position += movevelocity * Movesp * 4f *Time.deltaTime;
    }
}

It is a longer example than before. You can copy it, but typing it yourself and following what each part does is also a useful way to learn.

How the input works

Input.GetAxisRaw("Horizontal") reads Unity's built-in horizontal input axis in the input setup used by the tutorial. Pressing A produces a negative value, while D produces a positive one.

The code chooses Vector3.left or Vector3.right based on that value, then adds the resulting displacement to transform.position. This gives us horizontal movement. The original prose accidentally calls it vertical movement at one point.

Attach and configure the script

Return to Unity and drag the script onto the red-ball object named 예시 (“Example”). If you run the scene immediately, it may look as though nothing happens because Movesp starts at zero.

Select the object and scroll to its Move (Script) component in the Inspector. Find Movesp and try changing it to around 50, as the original lesson suggests. There is no screenshot for this step: the author notes that their capture tool was broken.

The article then points out that the object does not yet have a Rigidbody and uses that as the transition to the next lesson.

Editorial notes: this exact code moves transform.position directly and does not use the retrieved rigid field, so a missing Rigidbody does not by itself explain a failure to translate the object. FixedUpdate runs on the physics timestep, not once per rendered frame as the inherited comment suggests. The unused moove field and original input API are retained as part of the archived example. For physics-driven movement, use an approach appropriate to the Rigidbody and the Unity version you are working with.

Moved here from Tistory

I migrated this post from my Korean Tistory blog, I am Jason Lee, to this website and translated it into English. My writing and projects now live together in one place.

The original publication date, code examples, and screenshots are preserved. Editorial notes clarify known issues in the original material.

Original post on Tistory English edition · Aug 30, 2026
← Back to all articles