Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Maybe its a Photon Bug

Discussion in 'Multiplayer' started by Livindaki, Jul 24, 2019.

  1. Livindaki

    Livindaki

    Joined:
    Jun 13, 2017
    Posts:
    49
    I Wrote this very simple Script to check the reason of the error that i got with my other project .
    I Am using photon Pun 2

    Code (CSharp):
    1.  
    2. using Photon.Pun;
    3. using Photon.Realtime;
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using UnityEngine;
    7. using Photon;
    8. using UnityEngine.UI;
    9.  
    10. public class Start_Here : MonoBehaviourPunCallbacks {
    11.  
    12.     public GameObject prefab;
    13.     private GameObject My_Prefab;
    14.     private PhotonView PV;
    15.     public Transform parents;
    16.     public InputField InputText;
    17.  
    18.     public TextMesh txt;
    19.     void Start ()
    20.     {
    21.         if (!PhotonNetwork.IsConnected)
    22.             PhotonNetwork.ConnectUsingSettings();
    23.         PhotonNetwork.LocalPlayer.NickName = "Tamim"+Random.Range(1,1000).ToString();
    24.         InputText.text = "Tamim";
    25.     }
    26.  
    27.     public override void OnConnectedToMaster()
    28.     {
    29.         Debug.Log("We Are Connected to " + PhotonNetwork.CloudRegion + " ServerSettings!..........");
    30.         PhotonNetwork.AutomaticallySyncScene = true;  
    31.         PhotonNetwork.JoinLobby(TypedLobby.Default);      
    32.     }
    33.  
    34.     public override void OnJoinedLobby()
    35.     {
    36.         RoomOptions ro = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 10 };
    37.         PhotonNetwork.JoinOrCreateRoom("RG5", ro, TypedLobby.Default, null);
    38.     }
    39.     public override void OnJoinedRoom()
    40.     {
    41.         My_Prefab = PhotonNetwork.Instantiate("Sphere", new Vector3(0, 70, 0), Quaternion.identity, 0);
    42.         My_Prefab.transform.SetParent(parents);
    43.         PV = My_Prefab.GetComponent<PhotonView>();
    44.         txt = My_Prefab.GetComponentInChildren<TextMesh>();
    45.         if (PV.IsMine)
    46.             PV.RPC("Change_Name1", RpcTarget.All, InputText.text);  
    47.     }
    48.     [PunRPC]
    49.     public void Change_Name1(string ss)
    50.     {
    51.         InputText.text= ss + Random.Range(1, 100).ToString();
    52.     }
    53.     public override void OnPlayerEnteredRoom(Player newPlayer)
    54.     {
    55.         Debug.Log("Player Enterd The Room");
    56.     }
    57.     void OnGUI()
    58.     {
    59.         //GUI.Label(new Rect(50, 10, 400, 500 + 20), PhotonNetwork.NetworkClientState.ToString());
    60.         //2 += 5;
    61.     }
    62. }
    1-every client i run i got the error
    here i run two clients , and got two errors .
    2- InputText.text doesn't change ??
    Look like photon cant find the method. but it exist ????!!!!


    Any idea Please ?

    PhotonView with ID 1001 has no method "Change_Name1" marked with the [PunRPC](C#) or @PunRPC(JS) property! Args: String
    UnityEngine.Debug:LogError(Object)

    PhotonView with ID 2001 has no method "Change_Name1" marked with the [PunRPC](C#) or @PunRPC(JS) property! Args: String
    UnityEngine.Debug:LogError(Object)
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    The RPC Function needs to be on a script that is attached to your network prefab. I'm guessing the script you posted isn't?
     
  3. Livindaki

    Livindaki

    Joined:
    Jun 13, 2017
    Posts:
    49
    The RPC Function needs to be on a script that is attached to your network prefab. I'm guessing the script you posted isn't?

    and the call of the RPC function is it need to be on a script that is attached to my network prefab ? or can i call it out of that script ?
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    You can call it from anywhere that has a reference to the target network object.
     
  5. Livindaki

    Livindaki

    Joined:
    Jun 13, 2017
    Posts:
    49
    can i have the photonview component in an item list thats mean my player is an item list that had text and button and image ?
     
  6. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    I'm not sure exactly what you mean.

    Your player prefab can have a canvas attached with text and buttons and image UI components.