-
-
Save alxcancado/679dd36c71371c939de0 to your computer and use it in GitHub Desktop.
ADDED Font selection;
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; | |
// 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