Search Unity

The speed of the Scroll Speed not changed

Discussion in 'Scripting' started by HungPark, Dec 17, 2019.

  1. HungPark

    HungPark

    Joined:
    Feb 28, 2017
    Posts:
    81
    Hi!

    1. I changed the Scroll speed integer of the GameController from -2.0 to -4.0 to make the background speed(Scroll speed) faster.

    2. Two more objects are added in Prefabs(from 2 to 4) to make more obstacles(enemies).
    The new two objects have one trigger box-collider between them.

    3. The app is exported into Android Studio successfully. But when it is downloaded into smartphone(Galaxy s9), the speed of the Scroll(background) is the same as the previous version, I mean, not changed.

    How to fix this issue?

    I have tried to solve this issue a lot, but failed.
    Your help will be very appreciated.

    Thank you.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Post your code.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Have you tried printing the scroll speed out onscreen to see if it actually is different?
     
  4. HungPark

    HungPark

    Joined:
    Feb 28, 2017
    Posts:
    81
    Hi! StarManta and Kurt

    The speed made faster in the Unity Editor 2019.2 of the Desktop which I am working with,
    when I change the scroll speed from -2 to -4.

    But on the Smartphone(Galaxy 9) where It is downloaded, it is the same as previous version( as with -2)
    I don't understand what you say : "try printing the scroll speed out onscreen to see if it actually is different ?"

    Thank you.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    It depends on the script and what you actually mean by scroll speed. Your code will tell a lot. For example you could be scrolling on Desktop with your mouse scroll wheel, and you're increasing the speed by applying a multiplier to the scroll wheel input. Obviously that method would change nothing to scroll speed via a touch interface.

    No idea what your issue is because you're keeping the code which implements it all to yourself though.

    As for printing the scroll speed, what don't you understand? You're typed -4 into some field, print that field to the screen to make sure it is actually -4 at runtime while you are actually scrolling. For all anyone knows when on the phone some code in your game is changing it back to -2.

    When you're trying to debug issues, you have to be quite liberal with adding debugging code. Add Debug.Log statements all over the place, outputting pretty much anything relevant. Or output the data directly to the screen. You add enough debugging and you almost always will find one of your assumptions was wrong about how your code is working, and that leads you towards the solution as you debug further.
     
  6. HungPark

    HungPark

    Joined:
    Feb 28, 2017
    Posts:
    81
    HI! Joe,
    Let me explain the issue again.

    1. My app is 2D endless running game.
    2. I want the speed of the background of the game faster because it is too slow. So,
    3. I changed the integer from -2 to -4 in the filed of Scroll Speed of Game control(script) of the GameController.
    4. This made the speed of the background(scroll speed) faster (with-4) successfully on the screen of the Unity Editor when I play it. My Unity Editor is installed on desktop.
    5. It can be exported successfully into Android Studio, and debugged on Galaxy s9 smartphone.
    6. But when I play this app on Galaxy s9, the speed of the background of the game is the same as that of the previous version(same as with -2). I mean the the scrolling speed of the background is not changed when it is played on my smartphone Galaxy s9.

    I need your instruction to fix this issue.

    Thank you.
     
  7. HungPark

    HungPark

    Joined:
    Feb 28, 2017
    Posts:
    81
    Hi! Joe,
    This app is already uploaded on google plays store(Beta).

    Thank you.
     
  8. HungPark

    HungPark

    Joined:
    Feb 28, 2017
    Posts:
    81
    Hi! Joe,

    The previous version of this app is already uploaded on google play store(Beta)
    Doesn't this affect on the upgraded speed of the Scroll speed?

    Thank you.
     
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
     
    satchell likes this.
  10. HungPark

    HungPark

    Joined:
    Feb 28, 2017
    Posts:
    81
    Hi! StarManta,

    Which code do I post? I have so many codes.

    Thank you.
     
  11. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    You have an engineering problem. You made a change and it did not affect behavior the way you thought.

    Since you seem unwilling or unable to post relevant code, you leave us no choice but to loosely speculate vague things that might be going wrong.

    Here's my speculation of possible reasons you are seeing a problem:

    - you changed the number but something else (such as Unity deserialization) overwrote it

    - you changed the number but didn't Apply it to the prefab

    - you changed the number but didn't save the scene

    - you didn't rebuild the binary with the newest number in it

    - you changed a number, but it was a completely-different number unrelated to scroll speed.

    - you didn't actually change the number for some other unspecified reason

    - what you think is scroll speed is not actually scroll speed

    - etc etc etc. There are literally THOUSANDS of other reasons it might fail.

    Do you see the problem here? Now, I stand by my original response far above here: if you don't understand your "so many codes" well enough to post the specific code snippet you think is relevant, the only suggestion I have for you is to display the scroll speed on the screen on the device. This will at least BEGIN to give you a clue where to focus your engineering efforts.

    If you are unable to put a Canvas and a UnityEngine.UI.Text object onscreen in order to display this quantity, please review UI tutorials.

    Otherwise, I have no further suggestions, I'm sorry.
     
    Joe-Censored likes this.
  12. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Your issue is regarding scroll speed, so post the code related to scroll speed and scrolling, whatever that means for your game.
     
  13. HungPark

    HungPark

    Joined:
    Feb 28, 2017
    Posts:
    81
    Hi, Gentlemen,
    The followings are thought to be the related codes.

    1. GameControl.

    using UnityEngine.SceneManagement;

    public class GameControl : MonoBehaviour
    {
    public static GameControl instance;


    public float scrollSpeed = -4.0f;


    2. ScrollingObject

    public class ScrollingObject : MonoBehaviour
    {
    private Rigidbody2D rb2d;

    void Start ()
    {
    rb2d = GetComponent<Rigidbody2D>();
    rb2d.velocity = new Vector2(GameControl.instance.scrollSpeed, 0);
    }


    3. Repeating Background.
    public class RepeatingBackground : MonoBehaviour
    {
    private BoxCollider2D groundCollider;
    private float groundHorizontalLength;
    private readonly Vector2 groundOffSet;

    void Start ()
    {
    groundCollider = GetComponent<BoxCollider2D>();
    groundHorizontalLength = groundCollider.size.x;
    }

    void Update ()
    {
    if(transform.position.x<-groundHorizontalLength)
    {
    RepositionBackground();
    }
    }
    private void RepositionBackground()
    {
    Vector2 groundOffSet = new Vector2(groundHorizontalLength * 2f, 0);
    transform.position = (Vector2)transform.position + groundOffSet;
    }
    }


    I am waiting for your instructions.

    Thank you.
     
  14. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Did you display the value of that variable in the running binary?
     
  15. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Setting "public float scrollSpeed = 4.0f" in code doesn't do anything if it was already serialized as another value in the inspector. If you changed it in the inspector, you need to make sure that instance is the one you're finding at GameControl.instance.

    Outputting the value of GameControl.instance.scrollSpeed inside ScrollingObject.Start is the next thing I'd check.
     
  16. HungPark

    HungPark

    Joined:
    Feb 28, 2017
    Posts:
    81
    Hi,

    To Kurt,
    I displayed the value of that variable(-4) only in the field of Scroll Speed of Game Control(script) of GameController.


    To Joe,

    public class ScrollingObject : MonoBehaviour
    {
    private Rigidbody2D rb2d;

    void Start ()
    {
    rb2d = GetComponent<Rigidbody2D>();
    rb2d.velocity = new Vector2(GameControl.instance.scrollSpeed, 0);
    }

    void Update ()
    {
    if(GameControl.instance.gameover == true)
    {
    rb2d.velocity = Vector2.zero;
    }
    }
    }


    Thank you.