Unity - 网络管理器在Unity Editor外部无法正常工作

时间:2018-04-20 13:29:24

标签: unity3d networkmanager

我在Unity制作游戏,我想在某个屏幕上实例化网络管理器,所以我使用预制件作为网络管理员,我的代码如下: -

void Start()
{
    Transform cloneNetworkManager = Instantiate(networkManager, new Vector3(0, 0, 0), Quaternion.identity);
    NetworkManagerScript networkManagerScript = cloneNetworkManager.GetComponent<NetworkManagerScript>();
    networkManagerScript.OnButtonHost();
    ip = Network.player.ipAddress;
}

,网络管理员的代码如下: -

public class NetworkManagerScript : NetworkManager {
    public GameObject player;

    public void OnButtonHost()
    {
        networkPort = 10101;
        playerPrefab = player;
        StartHost();
    }

    public void OnButtonClient()
    {
        JoinMultiplayerScreenScript joinMultiplayerScreenScript = FindObjectOfType<JoinMultiplayerScreenScript>();
        networkAddress = joinMultiplayerScreenScript.ip.text;
        networkPort = 10101;
        playerPrefab = player;
        StartClient();
    }
}

现在的问题是当我在Unity编辑器中运行项目时,它正确运行,显示ip,并创建一个播放器。 like this image

但是当我将项目部署到Windows应用程序或Android应用程序时,它不会显示ip或创建播放器。 like this image

1 个答案:

答案 0 :(得分:0)

Problem solved

I discovered that I was deploying another scene.

I'm very sorry