1
\$\begingroup\$

I'm trying to learn how to make an offline LAN multiplayer game in Unity.

So for example, I make something that can send a text message and make a cube XD

Now this is my problem:

enter image description here

(When I send a message, try connecting to the server, or when I try to create a cube I should first click on the other window!)

StartServer:

    using UnityEngine;
using System.Collections;

public class StartServer : MonoBehaviour {
    public Transform Taghsimobj;
    public Transform Makan;
    public Transform CubeOBJ;

    public string MSG; 
    public string ResMsg;

    void Ress (string inres) {
        ResMsg = inres;

    }

    void OnGUI () {

        if (Network.peerType == NetworkPeerType.Disconnected)
        {
            if (GUILayout.Button ("StartServer"))
            {
                Network.InitializeServer(10, 25000);
            }
            if (GUILayout.Button ("Connect"))
            {
                Network.Connect ("192.168.1.101", 25000);
            }

        } 
        else 
        {
            if (GUILayout.Button ("CreatCube"))
            {
                Network.Instantiate (CubeOBJ, Makan.transform.position, Makan.transform.rotation, 0);
            }
            if (GUILayout.Button ("CreatChat"))
            {
                Network.Instantiate (Taghsimobj, this.transform.position, this.transform.rotation, 0);
            }
            if (GUILayout.Button ("SendMessage"))
            {
                GameObject.Find ("GameObject(Clone)").GetComponent<NetworkView>().RPC ("ResText", RPCMode.All, MSG);
            }
            MSG=GUILayout.TextField(MSG);   
            GUILayout.Box (ResMsg);
        }


    }
}

taghsim:

    using UnityEngine;
using System.Collections;

public class Taghsim : MonoBehaviour {

    void Start () {
    }

    [RPC]
    void ResText (string ResIn) {
        GameObject.Find ("Main Camera").SendMessage ("Ress", ResIn);

    }
}
\$\endgroup\$
2
  • \$\begingroup\$ You should not be sorry for your English. \$\endgroup\$ Jul 30, 2016 at 13:50
  • 4
    \$\begingroup\$ Did you try to test it with two computers? And did you try to run a debugger on that? The issue you're displaying seems related to the fact that your second window does not update the graphics because it's not on focus rather than related to network handling. \$\endgroup\$
    – Vaillancourt
    Jul 30, 2016 at 14:27

1 Answer 1

4
\$\begingroup\$

As far as I can see when you are not focusing a game instance, it goes to paused state

You must use: https://docs.unity3d.com/ScriptReference/Application-runInBackground.html

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .