Last active
January 27, 2024 10:32
-
-
Save mminer/1331330 to your computer and use it in GitHub Desktop.
Simple Unity script to create a scrolling marquee.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Marquee : MonoBehaviour | |
{ | |
public string message = "Where we're going, we don't need roads."; | |
public float scrollSpeed = 50; | |
Rect messageRect; | |
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; | |
} | |
GUI.Label(messageRect, message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've recently run into this and with the new UIDocuments the above method didn't work well for me. This was my fix. Hope it helps someone.
from there you can do stuff like
container.Add(message_label);
assumingLabel message_label;