PunRPC dont work

hello everyone, i made game like minecraft and i have mistakes, i instantiate objecte through PhotonNetworkRoom Object, write rps and call it. It worked, but now for some reason, when adding new colors, there is no (the old ones still work) is there a limit in the script for punrpc?

or what am I doing wrong? MyScript

 void CreateObjectInSceneeMagnetak(Vector3 spawnposition)
    {
        PhotonNetwork.InstantiateRoomObject(myPrefab[15].name, spawnposition, Quaternion.identity);
    }
[PunRPC]
    void RPC_CreateObject_MasterClientMagneta(Vector3 pos)
    {
        CreateObjectInSceneeMagnetak(pos);
    }
if (Input.GetMouseButtonDown(0))
        {
            if (pv.IsMine)
            {


                Ray ray;
                RaycastHit hit;
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (IsBuilding == true)
                {
                    if (Physics.Raycast(ray, out hit, 100.0f))
                    {
                        if (ColorID == 0)
                        {
                            if (hit.collider.tag == "Voxel")
                            {
                                spawnposition = new Vector3(Mathf.RoundToInt(hit.point.x + hit.normal.x / 2), Mathf.RoundToInt(hit.point.y + hit.normal.y / 2), Mathf.RoundToInt(hit.point.z + hit.normal.z / 2));
                                pv.RPC("RPC_CreateObject_MasterClientMagneta", RpcTarget.MasterClient, spawnposition);
                            }
                            else if (hit.collider.tag == "Ground")
                            {
                                spawnposition = new Vector3(Mathf.RoundToInt(hit.point.x + hit.normal.x / 2), Mathf.RoundToInt(hit.point.y + hit.normal.y / 2), Mathf.RoundToInt(hit.point.z + hit.normal.z / 2));
                                pv.RPC("RPC_CreateObject_MasterClientMagneta", RpcTarget.MasterClient, spawnposition);


                            }

}

Answers

  • Hi Roger,

    I'm sure there is no limit to the number of PunRPC functions. I will guess on of the conditional tests do not match. If you would like a suggestion, "simplify, simplify, simplify" :-)

    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;
    

    also you don't actually need to test == true

    if (IsBuilding)
    

    also as far as I can see the spawnPosition calculations are identical and if that is the case there is no need for all that code to be written twice.

    One way you can determine why your code isn't executing is with some Debug.Log lines to show you if IsBuilding is true, if the Raycast returns true, whether the ColorID is zero, etc.

    I'm fairly

  • Thx for answer @tleylan 😏, but solve this problem, I accidentally write space, that's why it couldn't find the function. Sorry for my englsih, his bad

  • ihor
    ihor
    edited June 2022

    @rogerpi It's notable for every coders, cuz even one character difference will take the definetly different function result😁

  • ага Игорь😂