I have a vehicle level that I set up using the Standard Assets vehicle sample level. The CarController script contains a float named Revs that I want to constantly update in the UI while driving around. I have this set up in the CarController script by converting it to a string and assigning it to a text variable which is linked in to the UI. This displays the variable but it only briefly flickers on-screen every so often, how can I make Unity constantly update the variable in the UI so I can always see what the current value is?
In set{} block of property call method to change revsText.text
For example:
private int revs;
public int Revs
{
get { return revs; }
set
{
revs = value;
ReflectValue(revs);
}
}
public void ReflectValue(int revs)
{
revText.text = revs.ToString();
}
Here you can use event instead of direct method ReflectValue() to have more decoupled and extendible code