Passing vars

Hey everyone, This is probably a simple question and I’ll probably feel dumb for asking it once I see the answer…but…I’m new to using javascript. Can someone tell me how to pass vars between scripts? I have one script that i’m using for my gui and I need to pass it a var from another script to display on the screen.

Thanks

“static” will make the variable accessible from other scripts
Check this page out for all the details.

http://unity3d.com/support/documentation/ScriptReference/index.Member_Variables_26_Global_Variables.html

The most repeatedly-asked question…or maybe that’s the one about 2-sided polygons. :wink: Anyway, it’s in the docs. Don’t use static variables unless you actually want them to be global. Often it’s more appropriate to use the GetComponent method.

–Eric

Awesome! Thanks! Can I have one more stupid question…for tonight 8)

I’m having a hard time understanding how to use GuiSkins etc… I’ve read through the docs but cant seem to make anything work. All i’m trying to do is to create a label with the color and font I want.

Don’t worry, OnGUI is kind of complex. :slight_smile: There are different methods of doing that (such as making an entirely new GUISkin), but here’s one of the simpler ways:

var myStyle : GUIStyle;

function OnGUI () {
	GUILayout.Label("Hi there!", myStyle);
}

Put that script on an object, select that object, and in the inspector, open up the “myStyle” variable. Drag the .ttf font you want onto the Font variable (about halfway down). Open up the Normal variable (near the top) and change the font color there. That should do it.

–Eric

Thanks! I finally figured out using the GUISkin. They seem to bury the Docs I need deeper down. LOL

:stuck_out_tongue: