- Home /
How do I set a GUI button's text using a string from another script?
I want to define the text if a GUI.Button using a string array, but my string is defined in a different script.
For example:
var tacticalvariable : tacticalvariables;
tacticalvariable = gameObject.GetComponent(tacticalvariables);
OnGUI () {
for (var i:int = 0; i<=5; i++) {
GUI.Button (Rect (270, 10 + (60 * i), 120, 40), tacticalvariable.phaser.FireMode[i]);
}
}
where tacticalvariable.phaser.FireMode[i] is a String array that is defined in tacticalvariables.js
I can't get anything to show on the button though - why not?
Hmmm. Have you taken a look at your script execution order? Are you absolutely sure you're doing your GetComponent call after your string array has been populated?
does it give any error?? if it doesnt give an error it means the string in another script is empty.. also check if the array is populated in another script bfore u execute it!!!
Your answer
Follow this Question
Related Questions
how to change a gui button texture 1 Answer
GUI & GUI Text Disappear When Publishing 6 Answers
IF in a GUI 2 Answers
Change Text of GUI Button from Script 2 Answers
Detect Text in GUI; Print 1 Answer