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 Haugkall · Jan 27, 2018 at 09:55 PM · buttonstringchange

Changing the string of multiple buttons when one button is clicked? (newb)

Here's my script, I want to change the string of multiple text objects depending on the value of a variable. This variable is suppose to change when a button is clicked, but I have trouble figuring out how to change the string of a button on runtime, this script isn't run in the text object itself but in an empty and needs to be called by the button, this is what is making it confusing for me I think.

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

 public class DialougeScript : MonoBehaviour {
 
     int one;
     int two;
     int three;
     int four;
     
     public Text text;
     Text text1;
     Text text2;
     Text text3;
     Text text4;
     
     // Use this for initialization
     void Start () {
         text1 = GetComponent<Text>();
         text2 = GetComponent<Text>();
         text3 = GetComponent<Text>();
         text4 = GetComponent<Text>();
         one = 1;
         two = 1;
         three = 1;
         four = 1;
         Dialouge();
     
     }
     
     public void Dialouge () {
     
     print ("test");
     
     if (one == 1){
         text.text = text1.ToString("Hello who are you?");
     if (two == 1){
         text.text = "I'm lost, where are we?";
     if (three == 1){
         text.text = "I wish I had something to eat.";
     if (four == 1){
         text.text = "I've got to go I think.";
         
         }
                 }
             }
         }
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 

This is what I'm confused about

" if (one == 1){ text.text = text1.ToString("Hello who are you?");"

and probably about other things as well such as what needs to be declared or called. I found the get component lines online, not sure if you're suppose to use those. Anyone knows how to do this? If I know how to change the string of a button I'm quite sure I could figure out the rest myself.

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

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

Related Questions

Change Player "Avatar" to a other "Avatar" by a GUI button click? 0 Answers

How to maintain button graphic on change scene? 0 Answers

Variable value does not change 0 Answers

click the button to change the character's sprite 1 Answer

How to change a public location,how to get a public variable 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