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 /
avatar image
0
Question by KnightRiderGuy · Dec 08, 2015 at 03:59 AM · c#uibuttonstringupdating

How Do I Change UI Text With A Button Click?

I have a UI text that I would like to change with a button click. How do I dod that with something like this?

 //UI Text Reference
     public Text MessageCentreText;
 
 public void GoScanner()
     {
         StartCoroutine (LoadS1());
         //Send to Sending script for message out to Arduino
         Sending.sendRed2 ();
 
 
     }
 
     IEnumerator LoadS1(){
         yield return new WaitForSeconds(3.5f); // wait time
         
     }
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

Answer by Superrodan · Dec 08, 2015 at 04:20 AM

The reference to change is ".text". For example:

 MessageCentreText.text = "this is my text";

Of course, that's only half of it. To make a button do that, you'd need to put it in a script. Something like:

 public void ChangeText(){
  MessageCentreText.text = "this is my text";
 }

Then, you would need your button to call that script. In the button setings, there is an "OnClick" section. You need to drag whatever has this script on it in there and assign the button to call ChangeText.

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 KnightRiderGuy · Dec 08, 2015 at 02:41 PM 0
Share

@Superrodan, thanks. You know I thought that what it was but when I tried it I was unable to get it to work.?

This is what I did:

 public void GoScanner()
     {
         StartCoroutine (LoadS1());
         //Send to Sending script for message out to Arduino
         Sending.sendRed2 ();
         $$anonymous$$essageCentreText.text = "SCANNING";
     }
 
     IEnumerator LoadS1(){
         yield return new WaitForSeconds(3.5f); // wait time
         
     }

avatar image KnightRiderGuy · Dec 08, 2015 at 04:45 PM 0
Share

@Superrodan, I even tried creating a new test scene and making a simple button on a canvas and adding the UI text element and then adding the script onto the button and it still does not work?

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class TextChange : $$anonymous$$onoBehaviour {
 
     //UI Text Reference
     public Text $$anonymous$$essageCentreText;
 
 
 
     //Scanner Button For $$anonymous$$essage
     public void GoScanner$$anonymous$$essage()
     {
         $$anonymous$$essageCentreText.text = "SCANNING";
     }
 }

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

41 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

Related Questions

I made an resume button, but I don't know how to code it to close my pause menu, any tips? 2 Answers

I need to move a sprite when an UI button is clicked 1 Answer

Adding a function to a UI 4.6 Button called on another game object in c# 0 Answers

Changing value in onClick, in button. 1 Answer

Change scene and play it by clicking UI Button? Scene does just load but not start playmode? 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