This should be easy, but I cannot work out how to do it, nor can I find any examples or posts regarding it.
I have three scripts, each handling a dynamic value - ScriptA has a ‘health’ variable (int), ScriptB has a ‘rotation’ value (float), and ScriptC has a ‘position’ variable (Vector3).
I’m trying to write a GUI script that will continuously write the current values of each of these three variables to a HUD.
How do I do that?
I’ve been using GetComponent in the Start function of my Gui script, but then the values don’t update dynamically.
As long as you put the assignment into the Update function, it is called at least 30 times a frame.
For instance, you get the initial value at the beginning of the program with awake/start. But you need to reassign the variables each frame.
If you have only one ScriptA, one ScriptB and one ScriptC assigned, you can do something like this:
private var sA;
private var sB;
private var sC;
function Start(){
sA = FindObjectOfType(ScriptA);
sB = FindObjectOfType(ScriptB);
sC = FindObjectOfType(ScriptC);
}
function Update(){
guiText.text = sA.health+"