Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How do I make my game object to keep moving to the right?

Discussion in '2D' started by eric56379, Nov 15, 2014.

  1. eric56379

    eric56379

    Joined:
    Mar 11, 2014
    Posts:
    89
    Hi, I am trying to make a Geometry Dash type of game, and I cannot seem to get this object moving. I tried many scripts but they all didn't work, even the sidescrolling script that comes with Unity. I also need it that when you press the Spacebar, you jump. How can I do this? Thanks, it's my first time trying Unity2D.
     
  2. Thril3r

    Thril3r

    Joined:
    Dec 6, 2013
    Posts:
    19
    Hi, this should make your object to keep moving to the right.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Move : MonoBehaviour {
    5.  
    6.  
    7.     public static float distanceTraveled;
    8.  
    9.     void Update () {
    10.         transform.Translate(5f * Time.deltaTime, 0f, 0f);
    11.         distanceTraveled = transform.localPosition.x;
    12.     }
    13. }
     
  3. playmonkey1

    playmonkey1

    Joined:
    Sep 20, 2013
    Posts:
    60
  4. eric56379

    eric56379

    Joined:
    Mar 11, 2014
    Posts:
    89
    Doesn't work... But there were no errors.