Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

A problem with Ruby tutorial

Discussion in 'Getting Started' started by Ramesis2nd, Sep 4, 2019.

  1. Ramesis2nd

    Ramesis2nd

    Joined:
    Jul 31, 2019
    Posts:
    1
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class RubyController : MonoBehaviour
    {
    // Start is called before the first frame update
    void Start()
    {

    }
    // Update is called once per frame
    void Update()
    {
    float horizontal = Input.GetAxis("Horizontal");
    Debug.Log (horizontal);
    Vector2 position = transform.position;
    position.x = position.x + (0.1f * horizontal);
    transform.position = position;
    }
    }

    The above is the code I copied from the Tutorial Ruby's Adventure
    The problem I am having is with the testing of this code

    When I enter game mode, the sprite begins moving to the right and responds to the left arrow key by moving left but then moves right again with no key pushed

    I've tried Unity versions 2018.3 and 2019.1 to no avail, have tried running the code one line at a time using the comment slashes and even initializing the variable horizontal to 0 in the void Start() section and as the 1st line of the void Update section

    Any help will be appreciated,
    Ram
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    5,815
    Your Debug.Log output should show you what is going on. I suspect it is different, depending on the left key press.