Intro, Text scrolling wrong direction (Down not Up)

I found this example it works, i modified it a bit for a skip feature and aligned it center. All works fine but it scrolls from the Top to the Bottom? I want the other way around > Bottom(start) to Top(stop) well it fades out but you know what i mean…

Is there a quick fix i can add to reverse it?

   public var intro : String[];
   public var off : float;
   public var speed = 12;

function Start (){
    audio.Play();
}
    

function OnGUI()
{
   if(Input.GetKeyDown("space")){
   print("Space Pressed");
   yield WaitForSeconds (2);
   Application.LoadLevel (0); //Test Main Menu
   }
    
   var Skip = new Rect((Screen.width/2)-10,(Screen.height/1)-30, 250, 80);
   GUI.Label(Skip, "Press (Space) To Skip Intro");
   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/1)*180*Mathf.Deg2Rad);
   GUI.color = new Color(1,1,1, alph);
   GUI.Label(new Rect(650,roff,(Screen.width/2)-50, 30),intro*);*

GUI.color = new Color(1,1,1,1);
}
}

There are two things you need to do:

  • Reverse the direction of the texts motion
  • Start the text at the bottom of the screen

You should be able to set Speed to a negative number via the Inspector to make text flow upward (but this alone will just render your entire view blank since it keeps scrolling up from the top of the screen).

You should also be able to set Off to a high enough positive number via the Inspector (or via Start) so the text start at the bottom of the screen. If you want to support multiple resolutions, check out Screen.height and base your off variable from that.

Here is an example how I do scrolling text, the downside of this method is that it is frame rate dependent. OnGUI() is called at least twice per Update(). But I guess depending on the functionality or appearance you are going for that won’t be a big deal.

I personally use a matrix to format to any aspect ratio, but this may not be the best approach to scale textures correctly. There has been some helpful answers to my post that make it seem like it could be possible to do it with the GUI.matrix, but you are probably better off using individual GUI Textures on empty game objects with a scaling script from:

Components > Rendering > GUI Texture

Seems excessive to do this for every single GUI component if you have a ton like I do. Hard to say what’s the best way to do this many suggest not even using OnGUI() and getting some 3rd party products from the Asset store such as 2D Toolkit.

I know some of this information isn’t related to your specific question I just kind of want to give others some info and a early warning if they are getting started with OnGUI(). I put in a ton of work into mine, and I’m not sure if I agree with using the GUI.matrix as the ultimate solution, it allows easy size and position for any screen, but not really that great with scaling it seems.

There are a few people who posted some useful answers so it may be possible to do it with the GUI.matrix. I have yet to try this one for example that looks like it could possibly work if you determined to go GUI.matrix:

Also scaling solutions like AspectRatioEnforcer seem like they would be good if you use GUI.Textures on individual game objects with the AspectRatioEnforcer script.

K anyways now that I gave my little speech since this stuff can be quite messy and people should be very careful before they commit to something if there could be better solutions for them.

Here’s an example of how I have GUI text float up the screen in my game, would work for labels or textures as well:

//easily edit GUI components
public GUIStyle potionStyle;

int GUIDepthInt = -1;

Vector3 matrixVector;
	
float native_width = 1280;
float native_height = 720;
	
float rx;
float ry;

int textUpCounter;

void Start()
{
    //scale for your matrix
    //this is where things get messy at different aspect ratios for your scale
    //if you always use a specific native width and height like 1280, 720
	rx = Screen.width/native_width;
	ry = Screen.height/native_height;

    matrixVector = new Vector3 (rx, ry, 1);

    potionStyle.normal.textColor = Color.red;

    textUpCounter = 0;
}

void OnGUI()
{
	
	if (GUIButtonsScript.gamePausedBool == true)
	{
		return;	
	}
		
	else if (potionObtainedBool == true)
	{
		GUI.depth = GUIDepthInt;
			 
		GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, matrixVector); 
			
		++textUpCounter;

        //this will center your text if you use the GUIStyle with "Upper Center" allignment
        //with the 1280, 720 formatting matrix
        GUI.Label (new Rect (640, 140 - textUpCounter, 0, 0), "+1 Health Potions!", potionStyle);

    }
}

So in this example you switch the healthPotionBool to true when you pick it up, it shows the text scroll up in center of screen.

I personally start a coroutine that destroys the health potion at the time the text should be disappearing off the screen.

I also enable this script when the player becomes fairly close to the potion.

Keep in mind that OnGUI() is VERY performance heavy calling twice per update, so if you are going to be using it on individual objects you will want to disable those scripts when out of range, and disable them again when the text display is not being used or just destroy the Game Object entirely.