Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

A problem with Ruby tutorial

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

  1. Deleted User

    Deleted User

    Guest

    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:
    7,578
    Your Debug.Log output should show you what is going on. I suspect it is different, depending on the left key press.
     
unityunity