Instance Objects Unity 5 C # Photon Networking Unity

2

I have a problem. I want to instantiate 2 objects but to instantiate it with the same object, and what I want is to instantiate the first object and after some way say that if the first object was instanced the second instancie instead of returning to instantiate the first.

I tried to do it this way:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NetworkManager : Photon.MonoBehaviour {

    public string Version;


   [SerializeField]private bool Join;

    void Start()
    {
        PhotonNetwork.ConnectUsingSettings(Version);
    }

    void OnConnectedToMaster()
    {
        PhotonNetwork.JoinOrCreateRoom("Lucha", new RoomOptions() {MaxPlayers = 2}, null);
    }

    void OnJoinedRoom()
    {
        if(Join == false)
        {
            PhotonNetwork.Instantiate("Jugador", transform.position, transform.rotation, 0);
            Join = true;
        }
        if(Join == true)
        {
            PhotonNetwork.Instantiate("Jugador2", transform.position, transform.rotation, 0);
        }
        Debug.Log("Join");
    }
}

But no ... I'm a player twice What I try to do is that if a person is already connected, that the next person who connects instead of instar player, instancie player2

    
asked by Alienx 15.11.2018 в 12:49
source

1 answer

0

Ok, I found the solution ... I had to use something from Photon .. practically this I did and it worked

if (PhotonNetwork.isMasterClient)
    {

        PhotonNetwork.Instantiate("Jugador", transform.position, transform.rotation, 0);
    }

    else
    {

        PhotonNetwork.Instantiate("Jugador1", transform.position, transform.rotation, 0);
    }

What I think, if I do not understand correctly, ask who is the main client of the room, and the rest speak alone, thanks for everyone's answers! a saludote

    
answered by 15.11.2018 / 18:05
source