Problem with RPC - GUI


I have an Account Creation GUI where I enter Username, password ,...

then I use a RPC to tell the server to insert the Account in the database and then Send an RPC back with Successfull or not.

This is working perfectly!

But I dont want to have my RPCs in my GUI Script. So I wanted to put the RPCs to another script.

The Registration Successfull RPC is calling a function to open a GUI Popup, so I need to use "AddComponent" on my RPC Gameobject. Ok now to the problem: When I use AddComponent("MyGUIScript") I have 2 GUI's! :( But I only want to use a function in MyGUIScript and not to have a completly new GUI. How to do this? Making the function static will not solve the problem because it is calling other functions in the GUI, and making all functions static isnt very fine.

So my question: How to call a Function in a GUIScript without using AddComponent, because this will create a second GUI?

Thank you very much.

Here is a little code Snippet:

Send this to server

function CreateAccount (username : String, password : String, email : String) {}

Get this from the server and Call RegistrationSuccessfull in the GuiScript (In this example the RPC is in the GUI so I can call RegistrationSucessfull without using AddComponent. But this doesnt work when I put the RPC into another Script.

function CreationStatus (status : int){
    if(status == 1){

You can use

var script : MyGUIScript = UnityEngine.Object.FindObjectOfType(MyGUIScript);

then you can call functions on it as you like

Another way to do it would be to use the singleton pattern - check this page on the wiki for ideas:


for making sure you have a component added to the same gameobject, add this above the class definition:




@script RequireComponent(MyGUIScript)