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 FoodFighter · Jan 30, 2015 at 04:42 PM · uigameobject

Changing many UI Text with UI Button clicked

I'm new about 4.6 ui style.

I can make the button do easy and specific action like change scene, change object, call object, destroy object.


Now I have a problem. I want to change list of ui text like this

  • Text1 (Shown and Enabled)

  • Text2 (Hide and Disabled)

  • Text3 (Hide and Disabled)

Above name are name object which I haven't tagged yet.

And 2 Button : Previous and Next


Now I can change Text1 to Text2 by setActive but from on click setting I can do once only.

If I want to destroy first next and enable another button which do for second next, it's may expensive.


What method I should do?

  1. Add array for gameobject name and setActive by ("Text"+i) = false, ("Text"+i+1) = true and looped

  2. Script controller which I can use with both button in once

  3. Use arraylist or enum ?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rob5300 · Jan 30, 2015 at 06:51 PM

If you want to have a 'toggle' system where you swap which UItext is enabled, try this:

 public void TextSwap(){
     Text1.SetActive(!Text1.enabled);
     Text2.SetActive(!Text2.enabled);
 }

This will set the Active state of the object to opposite of what it already is, causing it to toggle.

Sorry if this isn't what you mean, your description isn't that clear. Maybe provide code if this isn't helpful.

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
avatar image
0

Answer by FoodFighter · Feb 08, 2015 at 02:11 AM

Below code is my hard try to answer my question

I do 2 methods for each button and use array to keep the text I want to show.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class Test : MonoBehaviour {
     
     int index;
     
     string[] texts = new string[]{"ABC","DEF","G","HIJ"};
 
     Text word;
 
 
     void Start()
     {
              int index = 0;
              word = GameObject.Find ("Text").GetComponent<Text>();
              word.text = texts[index];
         }
 
     public void next()//Void for Next Button
     {
             if(index!=texts.Length){
                  index++;
 
                  word.text = texts[index];
                  print(texts[index]);}
 
         if(index==texts.Length)
         {
                  index=texts.Length;
             print ("This is last word");
         }
     }
 
     public void previous()//Void for Previous button
     {
             if(index!=0){
                 index--;
 
                 word.text = texts[index];
                 print(texts[index]);}
             if(index==0)
             {
                 index=0;
                 print ("This is first word");
             }
         }
 
 }



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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

4.6 Anchor a gameObject to a canvas 0 Answers

How to remove objects from a list ? 3 Answers

How to move a Game Object from a script not attached to it. 1 Answer

gameObject.SetActiveRecursively 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