- Home /
Change textAsset.text
Help!!!
Inside the box is a button that says next and lines of text. What I want is when I click the button the previous text asset will be changed with new text asset.
Here is my code:
var juan1 : TextAsset;
var hari1 : TextAsset;
var holdText : TextAsset;
var tooltipStyle : GUIStyle;
var tex1 : Texture;
function OnGUI()
{
if (guiOn)
{
tooltipStyle.padding = RectOffset();
tooltipStyle.contentOffset = Vector2();
holdText = juan1.text
GUI.Box(new Rect(10, Screen.height - 100, 1350, 1200), holdText.text, GUI.tooltip);
PauseGame();
if (GUI.Button( Rect (15, Screen.height - 70, 180, 47), tex1, tooltipStyle))
{
holdText = hari1.text
}
}
}
Answer by MojopinStudios · Feb 04, 2013 at 02:46 PM
While you haven't stated what the actual problem is, I am going to assume you need to change to:
holdText.text = juan1.text
And
holdText.text = hari1.text
Instead of just the holdtext
. You cannot set a TextAsset
equal to a string
.
Sorry, yes, I need to change it. okay. so is there a way to change it? or any other class functions I can use?
What do you mean? Change the 2 lines which are assigning to holdText
to assign to holdText.text
ins$$anonymous$$d.
No, the holdText.text was supposed to hold the the juan1.text at first.
holdText = juan1.text
GUI.Box(new Rect(10, Screen.height - 100, 1350, 1200), holdText.text, GUI.tooltip);
PauseGame();
then if i click the button. the juan1.text will changed into hari1.text without cahnging the gui.box.
if (GUI.Button( Rect (15, Screen.height - 70, 180, 47), tex1, tooltipStyle))
{
holdText = hari1.text
}
Have you read what I wrote?! Change references to holdText
to holdText.text
Ie.
var juan1 : TextAsset;
var hari1 : TextAsset;
var holdText : TextAsset;
var tooltipStyle : GUIStyle;
var tex1 : Texture;
function OnGUI()
{
if (guiOn)
{
tooltipStyle.padding = RectOffset();
tooltipStyle.contentOffset = Vector2();
holdText = juan1.text
GUI.Box(new Rect(10, Screen.height - 100, 1350, 1200), holdText.text, GUI.tooltip);
PauseGame();
if (GUI.Button( Rect (15, Screen.height - 70, 180, 47), tex1, tooltipStyle))
{
holdText = hari1.text
}
}
}
sorry. well, I've tried to change. A new error showed, it says "Property 'UnityEngine.TextAsset.text' is read only"
Your answer
![](https://koobas.hobune.stream/wayback/20220613092130im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can't draw GUI.Label text on subpixel values 0 Answers
Make text appear and stay when clicking. 1 Answer
Variables in GUI not updating/changing? (javascript) 1 Answer
Change text value 3 Answers
Display message when OnMouseDown 2 Answers