- Home /
Duplicate Question
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);
}
}
Almost the same damn question was asked in THIS TOPIC earlier today, and probably countless other ones over the years.
By the way.. you mention in one of your comments below here that adding the "new" keyword to a GUI.Label has gotten rid of your error but now you cant see it still... Try capitalizing OnGUI() properly.
That was the trick! Thanks :D I used OnQui ins$$anonymous$$d of OnGUI...
Answer by deltamish · Apr 06, 2014 at 09:23 AM
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");
This gets rid of the errors but I cant see the text now...
are you sure Try maximizing the screen view this code should work
Answer by Eric5h5 · Apr 06, 2014 at 11:14 AM
There is no built-in function called "OnGui". https://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnGUI.html
Answer by drudiverse · Apr 06, 2014 at 09:21 AM
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.: https://docs.unity3d.com/Documentation/ScriptReference/GUI.Label.html
Answer by Nequium · Apr 06, 2014 at 10:56 AM
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#.