How to remove the warning "Implicit downcast"

Hello guys, I am with a little problem. There is a warning in my code when I compile that I don’t know how to remove. The warning message is:

" WARNING: Implicit downcast from ‘UnityEngine.Component’ to ‘UnityEngine.GUIText’ ".

In three lines, one of these is the line:

scoreValue = score.GetComponent( "GUIText" );

The full script is below, and besides the warnings, it works OK, just for information it is a script to manipulate GUI getting data from a “global object”.

#pragma strict



private var scoreValue : GUIText;

private var lifeValue : GUIText;

private var counterManager : CounterManager;



// We'll draw a gizmo in the scene view, so it can be found....

function OnDrawGizmos() {

	Gizmos.DrawIcon(transform.position, "stageGUI.tif");

}



function Awake() 

{

	// Finding the game objects

	var score : GameObject = GameObject.Find( "StageGUI/ScoreValueGUI" );

	var life : GameObject = GameObject.Find( "StageGUI/LifeValueGUI" );

	

	scoreValue = score.GetComponent( "GUIText" );

	lifeValue = life.GetComponent( "GUIText" );

	

	

	// This must be loaded in other level, never in the play level

	var counter : GameObject = GameObject.Find( "Counter" );

	if ( counter == null )

	{}

	

	

	counterManager = counter.GetComponent( "CounterManager" );

	

	//Setting values

	scoreValue.text = ""+ counterManager.getScore();

	lifeValue.text = ""+ counterManager.getLifes();

}

Don’t use quotes in GetComponent; that makes it return Component instead of the type (as well as being slower and more susceptible to typos). scoreValue = score.GetComponent(GUIText);

You should explicity cast the Components to GUIText yourself using “as” like this:

scoreValue = score.GetComponent(GUIText) as GUIText;

lifeValue = life.GetComponent(GUIText) as GUIText;

with texture it’s renderer.material.GetTexture(“_MainTex”) as Texture2D;