2

In my multiplayer game, im trying to spawn my player by instantiating it. The error i get when running my program says i am missing the photon view component, yet i have it set to the correct player prefab. Here is my code for my network manager which searches, joins & creates a room when ran. The OnJoinedRoom function is supposed to be spawning my player.

error -'Failed to Instantiate prefab: Player. Prefab must have a PhotonView component.'

code:

using UnityEngine; using System.Collections;

public class NetworkManager : Photon.MonoBehaviour {

// Use this for initialization
void Start () 
{
    PhotonNetwork.ConnectUsingSettings ("version 1.0.0");
}


void OnGUI()
{
    GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
}

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

void OnPhotonRandomJoinFailed()
{
    PhotonNetwork.CreateRoom (null);
}

void OnJoinedRoom()
{
    GameObject myPlayer = PhotonNetwork.Instantiate ("Player", new Vector3(300, 18, 1496), Quaternion.identity, 0);
}

}

This link is a picture of the players information in the inspector.

http://prntscr.com/4wa8f6

devon t
  • 55
  • 2
  • 8

1 Answers1

0

Have you checked that your GameObject actually has a Photon View component? If not, you will need to go to your "Player" game object in the Inspector and click on "Add Component" and select Photon View. Depending on what you're using the game object for, you may need to drag another component (for example, the Transform component) into the Observed Components field for that Photon View.

VIN
  • 6,385
  • 7
  • 38
  • 77
  • Refer to the picture - it clearly shows that there is a photon view component attached to the gameobject. – devon t Jan 31 '17 at 02:30