Gui label errors

I used this code (and similar but with the same errors). I also tried GuiLayout.label

GUI.Label(Rect(10,10,100,30),"Test");

The errors that I get:

Assets/Scripts/NetworkManager.cs(15,27): error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected

Assets/Scripts/NetworkManager.cs(15,21): error CS1502: The best overloaded method match for `UnityEngine.GUI.Label(UnityEngine.Rect, string)’ has some invalid arguments

Assets/Scripts/NetworkManager.cs(15,21): error CS1503: Argument #1' cannot convert object’ expression to type `UnityEngine.Rect’

I was using this script also without any errors but here I can’t see the text…

using UnityEngine;
using System.Collections;

public class NetworkManager : Photon.MonoBehaviour {

	

	void Start ()	
 	{
		PhotonNetwork.ConnectUsingSettings("alpha 0.1");
	}
	
	void OnGui()
	{
		GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
	}
	
	void OnJoinedLobby()
	{
		PhotonNetwork.JoinRandomRoom();
	}
	
	void OnPhotonRandomJoinFail()
	{
		PhotonNetwork.CreateRoom(null);
	}
}

Hi thats really simple
all you got to do is add “new” syntax before the Rect

GUI.Label(new Rect(10,10,100,30),"Test");

There is no built-in function called “OnGui”. Unity - Scripting API: MonoBehaviour.OnGUI()

you probably forgot OnGui function…

check this page, and also read through the other GUI elements it’s handy. you do a loop in ongui to create many gui elements in one frame as well by looping their rect position.:

Change your code to:

GUI.Label(new Rect(10, 10, 100, 30), “Test”);

You must have the “new” keyword before Rect if you are coding in C#.