Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Tettsure · Jul 28, 2015 at 09:28 AM · c#guibutton

How Do You Use GUIText to Move Through Multiple Texts?

I am trying to enable and disable text several times through the OnGUI command. It's easier to illustrate through an example. I have four different gameobjects with different text: text1, text2, text3, and text4. What I am trying to do is that when you click the GUIbutton, it will disable text1 and enable text2. When you click the GUIbutton again, it will disable text2 and enable text3. Click it again, text3 will be disabled and text4 will be enabled. As my code stands now, it only goes from text1 to text2, but not from text2 to text3 when I attach the following script to the text gameObjects (same script attached to several gameObjects).

     public GUIText previousText;
     public GUIText targetText;
     private GUIText target;
     
 
     // Use this for initialization
     void Start () {
         previousText = GetComponent<GUIText> ();
         target = targetText.GetComponent<GUIText> ();
     }
     
     // Update is called once per frame
     void OnGUI() {
         GUI.backgroundColor = Color.black;
         if (GUI.Button (new Rect (Screen.width - 120, Screen.height - 115, 120, 120), "I am button")){
 
             previousText.enabled = false; 
             target.enabled = true;
             
         }
     }

I do not know if this is possible or very complex when it would be easier to do it another way, like make each text a scene. Any help would be extremely appreciated in getting this code to work.

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

1 Reply

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

Answer by Positive7 · Jul 28, 2015 at 11:30 AM

Here is one of my older script it's with UI Text but you can get the idea using UnityEngine; using UnityEngine.UI;

 public class test3 : MonoBehaviour
 {
     public Text[] text;
     public static int i = 0;
     void Start () {
         text = GetComponentsInChildren<Text> ();
     }
 
     void OnGUI() {
         GUI.backgroundColor = Color.black;
         if (GUI.Button (new Rect (Screen.width - 120, Screen.height - 115, 60, 60), "Next")) {
             if (i < (text.Length - 1)) {
                 Next ();
             }
         }
         if (GUI.Button (new Rect (Screen.width -260, Screen.height - 115, 60, 60), "Prev")) {
             if (i > 0) {
                 Prev ();
             }
         }
     }
     void Next(){
             text[i+1].enabled = true;
             text[i].enabled = false;
             i++;
         }
     void Prev(){
         text[i-1].enabled = true;
         text[i].enabled = false;
         i--;
     }
 }
Comment
Add comment · Show 1 · 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 Tettsure · Jul 29, 2015 at 12:19 AM 0
Share

Thank you so much!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make a or array of GUI.Button's? 1 Answer

How to fire gui button on mouse right release 2 Answers

Distribute terrain in zones 3 Answers

GUI.Button is acting funky. 2 Answers

[C#] Read from a file and write in a button? 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