Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheGeekyDead · Dec 21, 2013 at 10:42 PM · scrollingreverse

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[i]);
    GUI.color = new Color(1,1,1,1);
 }
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Dec 22, 2013 at 12:21 AM 0
Share

(You can't use coroutines inside OnGUI - it will generate a compile error)

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Statement · Dec 22, 2013 at 12:18 AM

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.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheGeekyDead · Dec 22, 2013 at 12:27 AM 0
Share

Thanks for the reply, i just tried the

public var speed = -12; in the script. Then i removed that and added the -12 in the inspector but noting appears.

$$anonymous$$aybe it's off the screen now.

off -= Time.deltaTime * speed;

$$anonymous$$akes it disappear completely.

avatar image Statement · Dec 22, 2013 at 12:33 AM 0
Share

Ok, just changing the default value in the code to -12 won't work and I told you to change it via the Inspector (for a good reason) :)

The reason is that Unity have stored the value 12 since before (or whatever value you set it to via the Inspector). The default value is only used when resetting a component or when adding a new component. Select your object in the heirarchy, and modify the value using the Editor.

Secondly, you shouldn't have to change the direction in that other snippet of code. Undo your changes.

Thirdly, you are still required to set off either via the Inspector, or adjusting it at Start to match Screen.height.

avatar image Statement · Dec 22, 2013 at 12:37 AM 0
Share

Ex:

  • Set Speed -12 via the Inspector

  • Undo your change to the second line you commented on

  • Set Off to 400 via the Inspector

Depending on your resolution, you are likely to see the text start climbing up from somewhere midscreen. If you increase Off, it will start further and further down.

avatar image TheGeekyDead · Dec 22, 2013 at 12:43 AM 0
Share

Yeah i fixed that -12 via inspector, sorry i miss read it. Im slow tonight it's working perfect now thanks man.

avatar image Statement · Dec 22, 2013 at 01:01 AM 0
Share

In the Inspector Off just appears as a 0

Yes. So set it to a value like 400. (400 pixels down from top of screen). If text starts in middle, increase it to 800. But this is a brittle approach. If you set off = Screen.height; inside Start chances are that it would match up better.

Show more comments
avatar image
0

Answer by RyanZimmerman87 · Dec 22, 2013 at 01:05 AM

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:

http://entitycrisis.blogspot.gr/2010/11/automagic-gui-scaling-in-unity3d.html

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Dec 22, 2013 at 01:13 AM 0
Share

Unitys GUI is performance heavy but perhaps not so because of calling OnGUI twice (or even more than that) per frame, but the rendering is not batched so GUI elements are one draw call each.

avatar image TheGeekyDead · Dec 22, 2013 at 01:19 AM 0
Share

Ok thanks for the post, i got $$anonymous$$e working now, but i will defiantly take a look at that later, im doing a lot of different stuff trying to learn/figure it all out.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

RTS Style Camera Scrolling 8 Answers

Who Killed Who - Scrolling GUI Text 2 Answers

Texture wont scroll on y-axis. 0 Answers

How do I improve my doodle-jump-like scrolling? 0 Answers

How to properly ease out texture scrolling? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges