Disable Mesh Renderer but use it's GUI

Hi,

function OnTriggerEnter(other : Collider){
	if (other.gameObject.CompareTag("RocketTag")) {
		
		s1_02Fuel.Score += 10.0;
		renderer.enabled = false;
		audio.PlayOneShot(CoinSound);
		CoinCought = true;
	}
}

function OnGUI ()
{
	GUI.skin = GUICoin;
	
	if (CoinCought == true)
	{
	GUI.Label (Rect (270, y, 880, 100), "+10");
	
	y += -100*Time.deltaTime;

	}
}

My problem is. If the mesh renderer is false. The GUI.Label won’t show. What should I do to disable only the Mesh Renderer and show it’s GUI.Label?

Hope you guy’s understand me.

Thanks in advance

Mesh renderer has no effect whatsoever on GUI.Label.

Try this simple test and you’ll see:

public class ShowLabel: MonoBehaviour {
	void OnGUI () {
		GUI.Label(new Rect(10, 10, 300, 50), "Test");
	}
}

Attach the script above to a cube, disable the renderer, and you’ll still see the text.

Try the following to debug your problem:

  1. Make sure the object itself is not disabled, and the script is not disabled, otherwise the script won’t run.
  2. Try to check your “y” value, by using Debug.Log. If it’s < 0, that would explain, you’re drawing outside of the screen.
  3. Try removing the if statement. In order for a GUI.Label to work, you need to draw it every frame. If at one frame you do not call the GUI.Label() command, it will not be drawn in that frame. (Yes, GUI.Label is not the most efficient way to go).
  4. Consider using GUIText instead of GUI.Label. It’s more efficient and easier to use:

http://docs.unity3d.com/Documentation/Components/class-GuiText.html