Hi all im new on unity and im trying to do a scrolling text from right to left, that should scroll a lyric of a song.
Could someone tell me if there’s some function to do this. Or should i use a GuiText and translate it?
And how can i do a container for that text so it doesn’t come from the begining of the screen?
Thanks and regards.
Here’s a script I whipped up that should do the trick:
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 the message's rect if we haven't already
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 the 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);
}
}
It uses GUI.Label, though without much difficulty you could modify it to use a GUIText object instead.