4.6 UI Text Value With Script??

So i have a script returning a value but the new UI script hates me as all new things usually do so it wont return the ToString value from FreezeTimer.

Script looks like this:

#pragma strict

import UnityEngine.UI;
public var Text : Text;

static var FreezeTimer : int = 5;


function Start ()
{
    MyCoroutine();
   
}


function MyCoroutine()
{
    while(FreezeTimer > 0)
    {
        FreezeTimer --;
        yield WaitForSeconds(1);
    }
}

function update ()
{
    Text.text = FreezeTimer.ToString("0");
}

The scene setup looks like the following

you don’t need to create a new thread for an update to a question…
and if you followed the @Sushin 's suggestion it would work.

the optional parameter for the ToString() function needs to be a valid formatter string, “0” isn’t one of them. For your usage you could just leave it out (as suggested).

formatter strings

int.tostring() page

The only reason for why i tried “0” is because it doesnt work when i just let it out and leave it as ToString.() - Nothing shows up

I have it like the following and it still doesnt show anything at all.
Text.text = FreezeTimer.ToString();

Update

not

update

classic…

Thanks haha :smile:

Do you know why my coroutine goes 5, 3 , 0 instead of 5, 4, 3, 2, 1, 0?

copied the script and it runs fine here, 4, 3, 2, 1, 0… it’s not going to show 5 since you immediately decrement by 1 before the wait for a second.

anything else running in your project that would severely affect the frame rate?

FIXED

The Script was applied on 2 different objects so it decreased twice, instead of 1 for each second !