Home > Net >  How to change sub Scene at Unity whtn I use MIRROR NETWORK?
How to change sub Scene at Unity whtn I use MIRROR NETWORK?

Time:09-30

Hello? I try to do change scene while I use Mirror Network.

Firstly, this is a picture that my projects' scene structure and describe what I want to do: enter image description here

And this is a capture image of my unity projects that you can understand my jobs image.

enter image description here

I use this code at my projects.

This code at Server Project:

[ClientRpc]
private void ChangeSceneA()
{
    NetworkManager manager = NetworkManager.singleton;
    manager.ServerChangeScene("SceneA");
}

This Code at Client A :

[ClientRpc]
private void ChangeSceneA()
{
    Debug.Log("SceneA Open");
}

This code at Client B:

private temp = 0; // to make call this function just aonce.

[ClientRpc]
private void ChangeSceneA()
{
    if (temp < 1)
    {
        NetworkManager manager = NetworkManager.singleton;
        manager.ServerChangeScene("SceneA");
    }

    temp = 1;    
}

I got this error message from server project's console.

enter image description here

It says : There is already a player for this connection. UnityEngine.Debug:LogError (object)

Is there very nice guy to help me?

CodePudding user response:

I solved this problem. It was little bit easy.

Firstly I use this code to load new scene:

 SceneManager.LoadScene("SceneA");

And then, create GameObject variable as global:

[SerializeField]
private GameObject Player;

Set player at Unity editor and it will be player prefab that you set in here. enter image description here

Finally, add this code at Start function then it's done.

private void Start()
{
    if(Player.activeSelf == true && isClient)
    {
        DontDestroyOnLoad(Player);
    }
}

※ I will keep this question for other people who will have same problem with me.

  • Related