Scroll intro text

Hey there!

I am having a problem with how to do the intro to my game, I am going to have the story displayed on screen by having the text scrolled from top to bottom and fade in and out(at top and bottom) hope that makes sense,

so what would be the best way to do this? I have tried using the fade.js script on the wiki but I could not get the desired result.


GUI.Label(new Rect(0,-1000 + (Time.time*100),Screen.width, 1000),"Some long text");

Where -1000 and 1000 are the height of your text, and 100 is how many pixels per second you want it to move down.

How it works:

Time.time steadily increases from the beginning of your game, in terms of seconds. Multiplying this buy 100 makes it faster, thus you can use it for scrolling effects.

IF the intro screen is NOT at the beginning of your game, then use this instead:

First, define a global float variable named off.

Then, run these two lines:

off += (Time.deltaTime*100);
GUI.Label(new Rect(0,-1000 + off,Screen.width, 1000),"Some long text");

Time.deltaTime if added each frame will add up to one by the end of the second. Likewise, this will behave exactly the same as the above code, except it always starts when your script loads rather than when your game loads. (If your script is pre-placed, it will load when the scene it is in loads. Otherwise, it loads when it gets added.)

Hope this helps -- Flynn

EDIT: Sorry, I did not catch the part about it fading in and out.

That's not really possible with GUI calls.

I'll get back to you on that in another answer.


There is one more way of doing it in the GUI: If you define each line in your intro as a separate item on an array, it could be done like so:


public var intro : String[];
public var off : float;
public var speed = 100;
function OnGUI()
    off += Time.deltaTime * speed;
    for (var i = 0; i < intro.Length; i++)
        var roff = (intro.Length*-20) + (i*20 + off);
        var alph = Mathf.Sin((roff/Screen.height)*180*Mathf.Deg2Rad);
        GUI.color = new Color(1,1,1, alph);
        GUI.Label(new Rect(0,roff,Screen.width, 20),intro*);*
 *GUI.color = new Color(1,1,1,1);*
*using UnityEngine;*
*using System.Collections;*
*public class ScrollerTest : MonoBehaviour*
 *public string[] intro;*
 *public float off;*
 *public float speed = 100;*
 *public void OnGUI()*
 _off += Time.deltaTime * speed;_
 *for (int i = 0; i < intro.Length; i++)*
 _float roff = (intro.Length*-20) + (i*20 + off);_
 _float alph = Mathf.Sin((roff/Screen.height)*180*Mathf.Deg2Rad);_
 *GUI.color = new Color(1,1,1, alph);*
 _GUI.Label(new Rect(0,roff,Screen.width, 20),intro*);*_
 _*GUI.color = new Color(1,1,1,1);*_

The easiest way to do the fade in/out effect is to have each line of text be separate, and make an array of text lines. Then you can have a routine that fades the lines based on distance from top/bottom, which is basically what the high score list for this does.

The other way of doing it is by scrolling the texture offset of a plane which has your text as it's image. You'll have to play with the settings on the material, but you can scroll the offset like this:

off += (Time.deltaTime/10); renderer.material.SetTextureOffset(off);

Then you can apply a shader which sets the alpha on top and on bottom as transparent.

I would not recommend this as such a shader would have to be custom built, and I am not a shader expert in the least.

Also rendering such a texture would be tough, and add allot of size to your project as the texture resolution would need to be enormous.

Is there a way to delay the GUI from scrolling until after it is loaded? When I load this in the webplayer, it is half way up the screen by the time the sceen is loaded. When I used yeild waitforseconds I get the error: OnGUI() cannot be a coroutine

Have the text on a material and just have a script that moves the camera down. Gives the effect.

Use the translate/transform.