Problem with photonView

Hey guys, I am working on a networking system (in fact, I am converting my old one to Photon). Since PhotonNetwork.Instantiate requires to Instantiate by string, I am having some trouble. I am trying to photonView from an object that I just instantiated, but Unity is telling me I can't because its a "GameObject". I'll post the script and the exact errors bellow with the script I am trying to convert, any help would be really appreciated! Thank you in advance!

Error 1:
Type `UnityEngine.GameObject' does not contain a definition for `photonView' and no extension method `photonView' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
Error 2:
Type `string' does not contain a definition for `photonView' and no extension method `photonView' of type `string' could be found (are you missing a using directive or an assembly reference?)

Code:
[RPC]
public void Client_PlayerJoined(string Username, PhotonPlayer id)
{
Player temp = new Player();
temp.PlayerName = Username;
temp.OnlinePlayer = id;
PlayerList.Add(temp);
if(PhotonNetwork.player == id)
{
MyPlayer = temp;
GameObject LastPlayer = PhotonNetwork.Instantiate("RigidBodyPlayer", Vector3.zero, Quaternion.identity, 0) as GameObject;
LastPlayer.photonView.RPC("RequestPlayer", PhotonTargets.AllBuffered, Username);
temp.Manager = LastPlayer.GetComponent<UserPlayer>();
MyPlayer.PlayerName.photonView.RPC("RequestPlayer", PhotonTargets.AllBuffered, Username);
Debug.Log("Spawned Player");
}
}

Comments

  • Hey Borzi,

    A few notes about your code:
    LastPlayer.photonView.RPC("RequestPlayer", PhotonTargets.AllBuffered, Username);

    If you have a MonoBehaviour script, use GetComponent in order to access PhotonView of the GameObject. Also, please make sure that PhotonView is indeed attached to your Player. Alternatively, you can turn your MonoBehavior to Photon.MonoBehaviour. In this case you will be able to access PhotonView as you do it now.

    There is no need to send a username as RPC. The username is synced for everyone with PhotonPlayer.name
    public void Client_PlayerJoined(string Username, PhotonPlayer id)

    The parameter name id is a bit confuzing in this case, as the PhotonPlayer class already contains a property ID. So, it would be better to rename the parameter, instead of calling id.ID ;)

    Hope that helps.
  • Ahhhh sorry for my late reply, I did fix it using GetComponent so you were right I suppose! Thanks!