Switch marquee direction?

I’m using this code on my project, but i just can’t seem to understand how to change the code that it would scroll text from right-to-left instead of left-to-right. How do i do that? Can someone help me, please?

Also, if someone could also tell me how can i change the size of the font and the color on text attached to this code would be really nice too. Yes, i’m new to coding :slight_smile:

Just flip the rects x pos. Like this:

(I’ve added a bool so you can have both left or right)

using UnityEngine;
using System.Collections;

public class Marquee : MonoBehaviour {
    public string message     = "Where we're going, we don't need roads.";
    public float scrollSpeed = 50;
  
    Rect messageRect;

    public bool left; //if true it'll scroll left, else right

    void OnGUI () {
        if (messageRect.width == 0) {
            Vector2 dimensions = GUI.skin.label.CalcSize(new GUIContent(message));
          
            // Start the message past the left side of the screen
            messageRect.x      = -dimensions.x;
            messageRect.width  =  dimensions.x;
            messageRect.height =  dimensions.y;
        }
      
        messageRect.x += Time.deltaTime * scrollSpeed;

        if (messageRect.x > Screen.width)
            messageRect.x = -messageRect.width;

        if(!left)
            GUI.Label(messageRect, message);
        else
            GUI.Label(new Rect(-messageRect.x, messageRect.y, messageRect.width, messageRect.height), message);
    }
}

That was fast! :slight_smile: Thanks a lot! It start rolling at the middle of the screen and not in the right, but i think i’ll figure that out. Important thing is that it now goes right-to-left, like i wanted :slight_smile: Thanks again for your very quick reply, sir!

No worries :slight_smile:

I figured out the font size and color issue. I added GUIstyle to the code and i’m set :slight_smile:

public GUIstyle myStyle;




if(!left)

GUI.Label(messageRect, message, myStyle);

else

GUI.Label(new Rect(-messageRect.x, messageRect.y, messageRect.width, messageRect.height), message, myStyle);

Now i have figure out how to move the text at the bottom on the screen and starting of the text scrolling to the right edge of the screen…

just set the message rect y to something lower.

Got it. Now text is at the bottom of the screen, but X is giving me a hard time. If i add x+something, it does what i want and text starts at the right edge of the screen, but when it gets at the left side of the screen, it cuts back to the right side before all of the text has scrolled off to the left. I don’t know if you understand what i’m trying to say but anyway…

Dammit! It stopped working when I’m trying to put a whole lot bigger/longer text on string… What’s up with that?

Not sure. I’m gonna need more information than that :slight_smile: what’s your updated script? and how big is your string?

My bad. It’s still working, but I had -messageRect.x + 460 at line 51 (for the line to start coming from the right side of the screen) but when I changed the length of the text, it went so far to the right that it took a lot of time to appear on the screen and all the code progress (text scrolling) went all to hell with longer string.

using UnityEngine;
using System.Collections;

public class MainMenu : MonoBehaviour {

    public string message = "WELCOME TO THE UNITY VERSION OF THE TEKHAN ARCADE GAME BOMBJACK    CODED BY XXXX XXXXXXXX    THANKS TO RORY GREEN FOR THE GRAPHICS    AND MARKD COOKSEY FOR THE MUSIC     ALSO TO GAVIN HARVEY AND CLARE POMEROY FOR ALL THEY HELP";
    public float scrollSpeed = 45;
    public bool left;
    public GUIStyle myStyle;
   
    Rect messageRect;

    //GUIText StartGame;
    // Use this for initialization
    void Start () {

    }
   
    // Update is called once per frame
    void Update () {

        if (Input.GetKey ("space")) {
            Application.LoadLevel("Level_1");
        }

        if (Input.GetKey("escape"))
            Application.Quit();
    }

    void OnGUI ()
    {
        // Set up message's rect if we haven't already.
        if (messageRect.width == 0) {
            var dimensions = GUI.skin.label.CalcSize(new GUIContent(message));
           
            // Start message past the left side of the screen.
            messageRect.x = -dimensions.x;
            messageRect.width = dimensions.x;
            messageRect.height = dimensions.y;
        }
       
        messageRect.x += Time.deltaTime * scrollSpeed;
       
        // If message has moved past the right side, move it back to the left.
        if (messageRect.x > Screen.width)
            messageRect.x = -messageRect.width;
       
        if(!left)
            GUI.Label(messageRect, message, myStyle);
        else
            GUI.Label(new Rect(-messageRect.x, messageRect.y+540, messageRect.width, messageRect.height), message, myStyle);
    }

}

I’ve got it! Still don’t quite understand the script, but it’s now doing for me what I want. Scrolls my text starting from right side of the screen to the left side and when all the text gets to the left (disappears to the left) it starts over from the right side. Does the job now. I’m happy. Lines 45 and 51 were the key to get it working for me.

using UnityEngine;
using System.Collections;

public class MainMenu : MonoBehaviour {

    public string message = "WELCOME TO THE UNITY VERSION OF THE TEKHAN ARCADE GAME BOMBJACK    CODED BY XXXXXXXXXXXXX    THANKS TO RORY GREEN FOR THE GRAPHICS    AND MARK COOKSEY FOR THE MUSIC     ALSO TO GAVIN HARVEY AND CLARE POMEROY FOR ALL THEY HELP";
    public float scrollSpeed = 45;
    public bool left;
    public GUIStyle myStyle;
  
    Rect messageRect;

    //GUIText StartGame;
    // Use this for initialization
    void Start () {

    }
  
    // Update is called once per frame
    void Update () {

        if (Input.GetKey ("space")) {
            Application.LoadLevel("Level_1");
        }

        if (Input.GetKey("escape"))
            Application.Quit();
    }

    void OnGUI ()
    {
        // Set up message's rect if we haven't already.
        if (messageRect.width == 0) {
            var dimensions = GUI.skin.label.CalcSize(new GUIContent(message));
          
            // Start message past the left side of the screen.
            messageRect.x = -dimensions.x;
            messageRect.width = dimensions.x;
            messageRect.height = dimensions.y;
        }
      
        messageRect.x += Time.deltaTime * scrollSpeed;
      
        // If message has moved past the right side, move it back to the left.
        if ((messageRect.x-1000) > Screen.width)
            messageRect.x = -messageRect.width;
      
        if(!left)
            GUI.Label(messageRect, message, myStyle);
        else
            GUI.Label(new Rect(-messageRect.x-640, messageRect.y+680, messageRect.width, messageRect.height), message, myStyle);
    }

}