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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ToString ??

Discussion in 'Scripting' started by Quist, Jun 18, 2015.

  1. Quist

    Quist

    Joined:
    Feb 25, 2014
    Posts:
    284
    Im trying to convert my int to a string so i can use it as a Text to my UI.
    But i get the error "Cannot convert 'int' to 'String'."

    The asnwer might be obvious to a lot of you but it ain´t to, so please help :)

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. import UnityEngine.UI;
    4. public var TheText : Text;
    5.  
    6.  
    7. static var FreezeTimer = 5;
    8.  
    9.  
    10. function Start ()
    11. {
    12.     MyCoroutine();
    13.    
    14. }
    15.  
    16.  
    17. function MyCoroutine()
    18. {
    19.     while(FreezeTimer > 0)
    20.     {
    21.         FreezeTimer --;
    22.         yield WaitForSeconds(1);
    23.     }
    24. }
    25.  
    26. function update ()
    27. {
    28.     FreezeTimer.ToString();
    29.     TheText.text = FreezeTimer;
    30. }
     
  2. Sushin

    Sushin

    Joined:
    May 2, 2015
    Posts:
    25
    FreezeTimer.ToString() doesn't turn FreezeTimer into a string. It returns a string.
    Instead, try this.

    Code (csharp):
    1. TheText.text = FreezeTimer.ToString();
     
    NomadKing and Quist like this.
  3. Quist

    Quist

    Joined:
    Feb 25, 2014
    Posts:
    284
    I Went off from my computer for tonight, but i Will test this in a couple of hours when it becomes Morning.

    Thanks a lot for the Help! :)
     
  4. Quist

    Quist

    Joined:
    Feb 25, 2014
    Posts:
    284
    It doesnt give me the error anymore, but no text shows up :?