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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by MetalLord · May 12, 2012 at 12:55 AM · guistringguitext

Filling GuiText with contents from a string array

I wanted a simple system to display two lines of text,and every time i press the space bar,change the two lines to the next ones in a array,i assigned 6 lines in the inpector,but after i press the key for the second time,it load the next scene,without all the lines showing.

using UnityEngine; using System.Collections; public class sistemaconversa : MonoBehaviour { public string [] texto1; public string [] texto2; public GUIText tex1; public GUIText tex2; int i = 0; int o = 0; void Start () { i = texto1.Length; tex1.text = texto1 [0]; tex2.text = texto2 [0]; }

 // Update is called once per frame
 void Update () {
 
 if(Input.GetKeyUp("space"))
     {
 o +=1;        
 tex1.text = texto1 [+1];
 tex2.text = texto2 [+1];
 
 
     }        

if(o > i ) { Application.LoadLevel(Application.loadedLevel+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 Berenger · May 12, 2012 at 01:41 AM 0
Share

Set o and i as public, then observe how they behave in the inspector during runtime. There is probably something going here.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rutter · May 12, 2012 at 01:51 AM

I do see one thing:

 tex1.text = texto1 [+1];
 tex2.text = texto2 [+1];

Instead of [1], you might want [o]?

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 MetalLord · May 12, 2012 at 01:58 AM 0
Share

It worked,didn't know variables can be use to call array elements.

avatar image aldonaletto · May 12, 2012 at 02:18 AM 0
Share

You can use any expression to index an array.

avatar image
0

Answer by aldonaletto · May 12, 2012 at 01:55 AM

You're always showing the same messages (texto1[1] and texto2[1]). You should use the index o, and pass to LoadLevel when o gets == i (arrays range from 0 to Length-1):

... if(Input.GetKeyUp("space")){ tex1.text = texto1 [o]; // display the messages index o... tex2.text = texto2 [o]; o += 1; // then increment the index } if ( o >= i ){ // when o >= length, load level: Application.LoadLevel(Application.loadedLevel+1); } ...

Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

Set name for game 0 Answers

Appear after set number of seconds 2 Answers

What's wrong with my function? It keeps telling me 'loseText' is not a member of 'UnityEngine.GUIText'. Please help, please and thank you! 0 Answers

Fix Blurry UI text? 10 Answers

Gui text, ammo counter 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