Sending OnGUI Text on RPC

Hi Guys! Is there a way to show (in all clients) an GUI message trought RPC’s functions?

Example:

var collegamento:boolean=false;

function OnConnectedToServer(){
	collegamento=true;
}

function OnGUI(){
	if(collegamento){
		networkView.RPC ("Guialo", RPCMode.All, "Un giocatore si è connesso e lo sanno tutti");
		networkView.RPC ("Guialo", RPCMode.Server, "Un giocatore si è connesso ma lo sa solo il server");
	}
}

@RPC
function Guialo(text : String){
		GUI.Label(Rect(10,10,200,30),text);
	}

When I have a connection from a Client I receive this message: You can only call GUI functions from inside OnGUI.
Do you know anothery way? Thanks

Well, you’re on the right track there… except for that GUI call outside OnGUI()

What you’d need to do is set up a variable to hold the text that was sent over the network, and using it, set a flag so you can render the text on OnGUI()…

It’s a longer way around, but it should be the simplest way of getting that to work…

something like this:

var textString = "";
var showText = false;

function OnGUI()
{
    if (showText) GUI.Label(myRect, textString);
}

@RPC
function displayText(text: string)
{
    textString = text;
    showText = true;
}

function OnConnectedToServer()
{
    networkView.RPC("displayText", RPCMode.All, "display this text across all clients");
}

Hope this helps

Cheers

ooooYes! :slight_smile: Thanks!!! :slight_smile:

I post the script with two fixes (string instead of String and myRect)

var textString = "";
var showText = false;

function OnGUI()
{
    if (showText) GUI.Label(Rect(10,50,200,20), textString);
}

@RPC
function displayText(text: String)
{
    textString = text;
    showText = true;
}

function OnConnectedToServer()
{
    networkView.RPC("displayText", RPCMode.All, "display this text across all clients");
}