Text is not a member of UnityEngine.Component error

Im trying to make aScoreboard but I am getting this error

var gui : GameObject;
static var CurrentScore: int;

function Update ()  
{
	gui.GetComponent("GUIText").text = "Score: " + CurrentScore;
}

Gah, had written a nice reply then realised you were using Javascript rather than C#. Makes the answer somewhat simpler:

gui.GetComponent(GUIText).text = "Score: " + CurrentScore;

Basically, remove the " so you just pass in the type of object you’re expecting to get a result about, not a string.

Personally I never use Javascript so that might not work, in which care you might need something like

function Update()
{
var myGuiText : GUIText;
myGuiText = gui.GetComponent(GUIText);
myGuiText.text = "Whatever";
}

That’s not really a very elegant answer as there are no checks to make sure that myGuiText is actually an object (might return null if GUIText doesn’t exist as a component on your object) and calling GetComponent every frame is slow.

Personally, I’d recommend looking at switching to C#. It’s a little more intimidating if you’re getting started but you’ll be better off in the long run (most examples etc focus on C# too).

As Fattie said too, the newer UI system is the way to go. It’s far more efficient to build and execute and I imagine there are plenty of samples around.

Surely the component type name would be Text

To find doco on the UI (some people still say “new” UI, but it is years old now)

surprisingly the Unity doco is quite good on this topic.