Search Unity

Help me see this code string rpc.

Discussion in 'Multiplayer' started by thepdone, May 27, 2015.

  1. thepdone

    thepdone

    Joined:
    Mar 15, 2015
    Posts:
    1
    I want thus.

    1.if client or inputusername no runing. server will no show string of outputusername in server or outputusername will = "";
    2. if 1 Impractical. I want code check ip client connecting in server if client connecting server will show ip of client but client disconnect. server will no show ip in server

    In other words i will do system online if client connecting in server will show username of client

    ---server---
    public int Port = 25001;
    public int num = 10;

    public string outputusername = "";

    public NetworkView nView;
    public NetworkPlayer player;

    void Start() {
    nView = GetComponent<NetworkView>();
    }

    void OnGUI()
    {
    if(Network.peerType == NetworkPeerType.Disconnected)
    {
    if(GUI.Button(new Rect(100,100,100,25),"Start Server"))
    {
    bool useNat = !Network.HavePublicAddress();
    Network.InitializeServer(num,Port,useNat);
    }
    }
    if(Network.peerType == NetworkPeerType.Server)
    {
    GUI.Label(new Rect(100,100,100,25),outputusername);
    }
    }

    [RPC]
    void TestCheck(string username)
    {
    if(Network.isServer)
    {
    outputusername = username;
    }
    }
    ---------

    ---client---
    public string IP = "192.168.1.2";
    public int Port = 25001;
    public string inputusername = "";

    public NetworkView nView;
    public NetworkPlayer player;

    void Start() {
    nView = GetComponent<NetworkView>();
    }

    void Update(){
    if(Network.peerType == NetworkPeerType.Client){
    nView.RPC("TestCheck",RPCMode.Server,inputusername);
    }
    }
    void OnGUI()
    {
    if(Network.peerType == NetworkPeerType.Disconnected)
    {
    if(GUI.Button(new Rect(100,100,100,25),"Start Client"))
    {
    Network.Connect(IP,Port);
    }
    }
    if(Network.peerType == NetworkPeerType.Client)
    {
    inputusername = GUI.TextArea(new Rect(100,75,110,25),inputusername);
    }
    }
    [RPC]
    void TestCheck(string username){}
    ---------