Skip to content

Instantly share code, notes, and snippets.

@alxcancado
Forked from mminer/Marquee.cs
Last active August 29, 2015 14:17
Show Gist options
  • Save alxcancado/679dd36c71371c939de0 to your computer and use it in GitHub Desktop.
Save alxcancado/679dd36c71371c939de0 to your computer and use it in GitHub Desktop.
ADDED Font selection;
using UnityEngine;
public class Marquee : MonoBehaviour
{
public string message = "Where we're going, we don't need roads.";
public float scrollSpeed = 50;
Rect messageRect;
// Select your font in the Unity Inspector
public Font f;
void OnGUI ()
{
// Setting Font
if(!f) {
Debug.LogError("No font found, assign one in the inspector.");
return;
}
GUI.skin.font = f;
// 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