I want to display text

No one answers me.

I just want to display a txt file on mouseDown in a gui
window. But gui does not support text.asset

Maybe someone can help me,

im really suffering.

reagards Joespace

Seeing as this appears to be your first post, I am wondering where you were expecting which people to answer you?

What you are describing does not have a simple, straight forward answer without the answering party doing a lot of your work for you - doing you a disservice in missed learning opportunity.

I suggest you start by reading the GUI tutorial: http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html
And viewing the introduction video: http://unity3d.com/support/resources/unite-presentations/in-game-gui-made-easy

maybe you can use StreamReader to read the text file, store it into a string variable and then display the string in GUI?

If it’s the TextAsset itself you’re having problems with, note that it’s not a string, it’s a TextAsset. As you can see in the docs, a TextAsset has a .text property (which is a string) and a .bytes property (which is a byte[ ] array). Since whatever you’re doing with your GUI probably requires a string, you need to use TextAsset.text to get the string value from it.

–Eric

I almost have it clear…so here it goes:

In the script: WchargedThrow.js

I have a controller attached to the main camera that throws a ball with a variable strength (the longer you hold the mouseDown…the farther it goes).

var chargeTime = 0.0;

I’d like to display this variable in a GUI Label on the screen.

I tried this in another script called chargeGUI.js:

function OnGUI () {
    	GUI.Label (Rect (10,40,120,20), WchargedThrow.chargeTime);
}

I got this error: An instance of type WchargedThrow is required to access non static member 'chargetime"…

Please advise.

Hi James,

I wonder if you can simply declare

var chargeTime = 0.0;

as

static var chargeTime = 0.0;

instead?

Just a thought
AC

Thanks Targos:

The variable charge time changes when the mouse is held down so I don’t know if it would be considered a “Static” Variable.

The real question I am finding is, how can I call a variable from another script into a GUI object to show the variable in real time… Like a progress bar, or just a number…

I dont think thats the definition of static in these terms, (out on a limb here guys) I think “Static” means “there is only one in the scene” so you can have a varible, and it could be changed from any number of other scripts, and it changes globally. so if 6 objects had a static var and you change one of them, they all change. The Lerpz platformer tut has definitions If I recall.

I think I see what you’re trying to achieve, you need the player to see how much charge-up they have from holding the mouse.

I tried to figure it out, but I dont seem to be handling the conversion of integers to strings. Can anyone see what needs to be done with this example?

 var chargeTime: String="press lmb";
 var chargeTimeInt:int= 0;
 
function Update () {
	if(Input.GetButton("Fire1")){
	chargeTime=chargeTimeInt.ToString;
	chargeTimeInt++;
	Debug.Log(chargeTimeInt);
	}
}
function OnGUI () {
       GUI.Label (Rect (10,40,120,20),chargeTime);
}

Confounding error messages dont really make any sense.

Cheers
AC

Missed a couple of brackets it would seem();

@MauiSage try this on an empty GO as a test

 var chargeTime: String="press lmb";
 var chargeTimeInt:int= 0;

 
function Update () {
	if(Input.GetButton("Fire1")){
	chargeTime=chargeTimeInt.ToString();
	chargeTimeInt++;
	Debug.Log(chargeTimeInt);
	}
}
function OnGUI () {
       GUI.Label (Rect (10,40,120,20),chargeTime);
}