Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Change Button Text ?

Discussion in 'UGUI & TextMesh Pro' started by dichterDichter, Aug 8, 2016.

  1. dichterDichter

    dichterDichter

    Joined:
    Oct 8, 2015
    Posts:
    13
    Hi,

    i have a script on my camera which moves the camera to a specific position.
    when i klick a button in my game i want to start the movement and change the button text from "move in" to "move out" then the camera ride is over.

    I tried to change the text from within the camera script but i just cant access the button text.
    In general, is it a good idea to access the button text from within the camera or are there better ways?
    How can i change the button text after something happened and change it to something different after clicking it again?
     
  2. dichterDichter

    dichterDichter

    Joined:
    Oct 8, 2015
    Posts:
    13
    Ah, after trying so much its that easy...
    Code (csharp):
    1. GameObject.Find("buttonName").GetComponentInChildren<Text>().text = "la di da";
     
  3. xtrsteve

    xtrsteve

    Joined:
    Jul 22, 2015
    Posts:
    8
    Thanks.
     
  4. matkoniecz

    matkoniecz

    Joined:
    Feb 23, 2020
    Posts:
    170
  5. jaat_kushagra

    jaat_kushagra

    Joined:
    Apr 11, 2020
    Posts:
    1
    thanks @dichterDichter it works well
    but i also want to change the color and font of text can anyone help me out
     
  6. StarArcher

    StarArcher

    Joined:
    May 23, 2020
    Posts:
    12
  7. Troy_Serapio

    Troy_Serapio

    Joined:
    Jun 25, 2020
    Posts:
    1
    Dude, how do you know what to put?(buttonName)
     
    Last edited: Jul 14, 2020
  8. papalaag

    papalaag

    Joined:
    Jul 23, 2020
    Posts:
    1
    the name of the button in your scene if you didnt change the name its called Button
     
  9. amnafirdous34

    amnafirdous34

    Joined:
    Jul 24, 2020
    Posts:
    1
    thankuuuu u literally saves me
     
    faosldkjfhf2 likes this.
  10. DexTroZ_08

    DexTroZ_08

    Joined:
    Aug 18, 2020
    Posts:
    1
    cant we do it from unity itself???
     
  11. creativetclily

    creativetclily

    Joined:
    Oct 20, 2020
    Posts:
    1
    I was able to change the button text in Unity by clicking the down arrow next to "Button" in the Hierarchy menu on the lefthand side of my screen. Once I clicked the down arrow the word "Text" appeared and on the right hand side of my screen in the Inspector. I was then able to edit the text/font/size/color. I hope this helps!
     
    Last edited: Oct 20, 2020
    tbvr, thathurtabit, emredesu and 3 others like this.
  12. unity_0342CC73C67D7833606D

    unity_0342CC73C67D7833606D

    Joined:
    Oct 4, 2021
    Posts:
    1
    This is what i have been looking for THANK YOU!
     
  13. REMCodes

    REMCodes

    Joined:
    Sep 16, 2020
    Posts:
    2
    Yes, we can do that from the engine. However, the poster was asking how to change it in a script.
     
  14. Set_X

    Set_X

    Joined:
    Dec 7, 2022
    Posts:
    1
    :) thank you!