c# - How to get a normalized value to change a UI text element in Unity? -


i have normalized value coming current position of animation. how convert text output depending on value within string?

for example

if (animation.time < 0.1) {     text = january; }  else (0.1 < animation.time < 0.2) {     text = february; } 

etc, way until 1, because of normalized value.

i realise code won't work @ all, think logic needed work, far i've had no luck.

edit, elaborated question. have slider moves depending on progression of animation, via converting animationtime normalized value slider fills in relation animation.

i'd take value of normalized time display current related date of animation, on screen, if animation shows years progression, slider moves , normalized value can have text count in months.

i hope makes more sense now.

to "month string" in unity this...

say have "3" ..

string monthstring = new system.datetime(1,3,1).tostring("mmmm"); debug.log("teste " + monthstring ); 

result, "march".

so make function

private string monthfromint(int m)  {  string monthstring = new system.datetime(1, m ,1).tostring("mmmm");  return monthstring;  } 

and use that.


regarding control structure need. mention "between 2 values". just

if ( 0.00f < t && t <= 0.23f ) here... 

i suggest kiss following. fill in values:

float t = animation.time (or whatever) string text = "?";  if ( 0.00f <= t && t <= 0.23f ) text = monthfromint(0); if ( 0.23f < t && t <= 0.41f ) text = monthfromint(1); if ( 0.41f < t && t <= 0.66f ) text = monthfromint(2); if ( 0.66f < t && t <= 0.68f ) text = monthfromint(3); ... etc ... if ( 0.91f < t && t <= 1.00f ) text = monthfromint(11); 

use "<" , "<=" above. hope helps!


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -