L
L
likel0vsky2020-11-08 13:04:21
Unity
likel0vsky, 2020-11-08 13:04:21

PhotonNetwork.Instantiate doesn't work. How to fix?

There is a line of code:

PhotonNetwork.Instantiate("Test", new Vector3(0,0,0), Quaternion.identity, 0);

There is this prefab in the resources folder, by the way, the Player will spawn before that, in the same way, but this particular line does not work. How can I fix this error?

Whole code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Realtime;
using ExitGames.Client.Photon;
using UnityEngine.UI;
using System.Threading.Tasks;

public class map : Photon.PunBehaviour
{
    public Text text;
    public int radius = 15;
    public Generator generator;
    public GameObject player;
    // Start is called before the first frame update
    void Start()
    {
        Destroy(GameObject.Find("Player"));
        PhotonNetwork.ConnectUsingSettings("1.0");
    }
   
    private void OnConnectedToMaster()
    {
        PhotonNetwork.JoinLobby();
    }

    

    public override void OnJoinedLobby()
    {
        PhotonNetwork.JoinRandomRoom();
    }

    public override void OnJoinedRoom()
    {
        if(PhotonNetwork.room.PlayerCount < 2)
        {
            text.text = "wait for players";
        } 
        else
        {
            PhotonNetwork.Destroy(text.gameObject);
        }

        
 
        player = PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);
        player.gameObject.tag = "Player";
        print(player.gameObject.tag);
        PhotonNetwork.Instantiate("Test", new Vector3(0,0,0), Quaternion.identity, 0);
    }



    public void OnEvent(EventData photonEvent)
    {
        if (photonEvent.Code == 1)
        {

        }
    }


    void OnPhotonInstantiate(PhotonMessageInfo info)
    {
        print("d");
    }


    void OnPhotonRandomJoinFailed()
    {
        PhotonNetwork.CreateRoom("play");
    }

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question