Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ar_khan30 · Aug 31, 2016 at 09:58 AM · changing

Changing Text of multiple Button if Pressed Button Text is equal to UI Text

I write that code Butt it is not working plz help me ... i am new developer on unity

using UnityEngine; using System.Collections; using UnityEngine.UI; using System;

public class Guess : MonoBehaviour { public Text mainText; public Button b1; public Button b2; public Button b3; public Button b4; public Button b5; public Button b6; public Button b7; public Button b8;

 String[] array; 
 void Start () {

     mainText = mainText.GetComponent<Text>();
     b1 = b1.GetComponent<Button>();
     b2 = b1.GetComponent<Button>();
     b3 = b1.GetComponent<Button>();
     b4 = b1.GetComponent<Button>();
     b5 = b1.GetComponent<Button>();
     b6 = b1.GetComponent<Button>();
     b7 = b1.GetComponent<Button>();
     b8 = b1.GetComponent<Button>();



     array = new string[8];
     array[0] = "Pakistan";
     array[1] = "India";
     array[2] = "Amarica";
     array[3] = "England";
     array[4] = "Room";
     array[5] = "Itly";
     array[6] = "Turky";
     array[7] = "Rausia";

    
     System.Random rn = new System.Random();
     int answer = rn.Next(8 ) + 1;
     mainText.text = array[answer];




 }
 
 // Update is called once per frame
 void Update () {


 }

 public void buttonRight1()
 {
     
    // String s = mainText.text;
     /*
     //suffle(s);
     if (b1.GetComponentInChildren<Text>().text == s)
     {
         check();

     }
     */
     if (b1.GetComponentInChildren<Text>().text == mainText.text)
     {
         
         b1.GetComponentInChildren<Text>().text = randomName();
         check();

     }


 }
 public void buttonRight2()
 {
     //String s = mainText.text;
     if (b2.GetComponentInChildren<Text>().text == mainText.text)
     {
         //b2.GetComponentInChildren<Text>().text = randomName();
         
         b2.GetComponentInChildren<Text>().text = randomName();
         check();
     }



 }
 public void buttonRight3()
 {
    // String s = mainText.text;
     if (b3.GetComponentInChildren<Text>().text == mainText.text)
     {
         b3.GetComponentInChildren<Text>().text = randomName();
         check();
     }

 }
 public void buttonRight4()
 {
    // String s = mainText.text;
     if (b4.GetComponentInChildren<Text>().text == mainText.text)
     {
         b4.GetComponentInChildren<Text>().text = randomName();
         check();
     }
 }


 public void buttonLeft1()
 {
     //String s = mainText.text;
     if (b5.GetComponentInChildren<Text>().text == mainText.text)
     {
         b5.GetComponentInChildren<Text>().text = randomName();
         check();
     }
 }
 public void buttonLeft2()
 {
    // String s = mainText.text;
     if (b6.GetComponentInChildren<Text>().text == mainText.text)
     {
         b6.GetComponentInChildren<Text>().text = randomName();
        check();
     }
 }
 public void buttonLeft3()
 {
     //String s = mainText.text;
     if (b7.GetComponentInChildren<Text>().text == mainText.text)
     {
         b7.GetComponentInChildren<Text>().text = randomName();
         check();
     }
 }
 public void buttonLeft4()
 {
    // String s = mainText.text;
     if (b8.GetComponentInChildren<Text>().text == mainText.text)
     {
         b8.GetComponentInChildren<Text>().text = randomName();
         check();
     }
 }
 /*
 public void suffle( String s )
 {
    
     if (b1.GetComponentInChildren<Text>().text == s)
     {
         check();
     }
     else if (b2.GetComponentInChildren<Text>().text == s)
     {
         check();
     }
     else if (b3.GetComponentInChildren<Text>().text == s)
     {
         check();
     }
     else if (b4.GetComponentInChildren<Text>().text == s)
     {
         check();
     }
     else if (b5.GetComponentInChildren<Text>().text == s)
     {
         check();
     }
     else if (b6.GetComponentInChildren<Text>().text == s )
     {
         check();
     }
     else if (b7.GetComponentInChildren<Text>().text == s)
     {
         check();
     }
     else if (b8.GetComponentInChildren<Text>().text == s)
     {
         check();
     }
 }
 */
 
 public String randomName()
 {
     
     array[0] = "Pakistan";
     array[1] = "India";
     array[2] = "Amarica";
     array[3] = "England";
     array[4] = "Room";
     array[5] = "Itly";
     array[6] = "Turky";
     array[7] = "Rausia";


     System.Random rn = new System.Random();
     int answer = rn.Next(8 ) + 1;
     return array[answer];
 }

 public void check()
 {
     
     
     while (b1.GetComponentInChildren<Text>().text == b2.GetComponentInChildren<Text>().text
            /* &&
             b2.GetComponentInChildren<Text>().text == b3.GetComponentInChildren<Text>().text
             &&
             b3.GetComponentInChildren<Text>().text == b4.GetComponentInChildren<Text>().text
             &&
             b4.GetComponentInChildren<Text>().text == b5.GetComponentInChildren<Text>().text
             &&
             b5.GetComponentInChildren<Text>().text == b6.GetComponentInChildren<Text>().text
             &&
             b6.GetComponentInChildren<Text>().text == b7.GetComponentInChildren<Text>().text
             &&
             b7.GetComponentInChildren<Text>().text == b8.GetComponentInChildren<Text>().text
             &&
             b8.GetComponentInChildren<Text>().text == b1.GetComponentInChildren<Text>().text

 */
         )
     {
         
         b1.GetComponentInChildren<Text>().text = randomName();
         b2.GetComponentInChildren<Text>().text = randomName();
         b3.GetComponentInChildren<Text>().text = randomName();
         b4.GetComponentInChildren<Text>().text = randomName();
         b5.GetComponentInChildren<Text>().text = randomName();
         b6.GetComponentInChildren<Text>().text = randomName();
         b7.GetComponentInChildren<Text>().text = randomName();
         b8.GetComponentInChildren<Text>().text = randomName();

     }
 }
 

}

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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Changing Sprites in Code (c#) help 0 Answers

Changing Player Position when hit by collider 0 Answers

Help with Changing Sprites in Code (c#) 0 Answers

position the player on the same position as an object 0 Answers

Material Changing c# 0 Answers


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