- Home /
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.
Thanks!
Create a 3D text in the Editor, this allows you to edits it position using the X, Y and Z axis. Now rotate the X-Axis by 45, then set alignment to "center".
Then create a script for the text, call it "TextIntro"(use Java) clear the script, then past this simple code:
function FixedUpdate () {
transform.localPosition.z += 1 * Time.deltaTime;
transform.localPosition.y += 0.5 * Time.deltaTime;
}
Hope this Benefits you.
Answer by Flynn · Jan 18, 2011 at 07:29 PM
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.
EDIT:
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:
JS:
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[i]);
GUI.color = new Color(1,1,1,1);
}
}
c#
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[i]);
GUI.color = new Color(1,1,1,1);
}
}
}
Use \n for line breaks in the Some long text, just adding. But great answer.
hello Flynn, thanks for your code to autoscroll. it's works perfectly but I board not successful to reverse the direction. Could you help me, please
for the reverse direction you would simply put a check to see where the current position is at... before the main draw for loop in the example..
if (mode == 1){ off += Time.deltaTime speed; } if (mode == 2){ off -= Time.deltaTime speed; }
//...loop code for
//...after flynn's draw code for block
if (roff > Screen.height) { mode = 2;}
if (roff < 0) { mode = 1;}
you probably have it all done by now though. just thought I would show you that it just takes a couple checks and a resetting of the check.. in my example above it just makes the text bounce up and down... very simple... gl
Answer by Eric5h5 · Jan 18, 2011 at 07:48 PM
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.
Answer by Justin Warner · Jan 18, 2011 at 07:25 PM
Have the text on a material and just have a script that moves the camera down. Gives the effect.
Use the translate/transform.
Answer by Flynn · Jan 18, 2011 at 07:34 PM
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.
Answer by spidarmen · Jun 22, 2012 at 10:05 AM
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