PHOTON PUN RPC HELPPP

Options

Hello I am reallly new to photon Pun and Unity ,I was trying to Open Doors When they satisfy a condition but The problem is that only the person Who Joins the Lobby can See Them Open and the player who created the lobby cant see the Doors Getting Opened, Here is the code, Please Help..

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Photon.Pun;


public class level2OpenDoor : MonoBehaviourPun

{

  [SerializeField]   private GameObject outputGB=null;

  [SerializeField]   private GameObject outputGB1=null;

  [SerializeField]   private GameObject outputGB2=null;

  [SerializeField]   private GameObject outputGB3=null;

  [SerializeField] private GameObject door;

  [SerializeField] private GameObject door2;

  private Animation anim;

  private Animation anim2;

   [SerializeField] GameObject door3;

   [SerializeField] GameObject door4;

   Vector3 openDoor;

    Vector3 openDoor2;

    Vector3 openDoor3;

    Vector3 openDoor4;

      private PhotonView view;

    int i=0;

    // Start is called before the first frame update

    void Start()

    {

        openDoor=new Vector3(door.transform.position.x,door.transform.position.y+100.34f,door.transform.position.z);

        openDoor2=new Vector3(door2.transform.position.x,door2.transform.position.y-100.0f,door2.transform.position.z);

         openDoor3=new Vector3(door3.transform.position.x,door3.transform.position.y+100.34f,door3.transform.position.z);

        openDoor4=new Vector3(door4.transform.position.x,door4.transform.position.y-100.0f,door4.transform.position.z);

       

            view=GetComponent<PhotonView>();

           

    }


    // Update is called once per frame

    void Update()

    {

        Debug.Log("updating");

       if(i==0)

       {

           this.photonView.RPC("checkDoor",RpcTarget.All);


       }

    }

  [PunRPC]public void checkDoor()

    {

        Debug.Log("chking");

         if(outputGB.GetComponent<level2OPbox>().finalVal==1&&outputGB1.GetComponent<level2OPbox>().finalVal==0&&outputGB2.GetComponent<level2OPbox>().finalVal==1&&outputGB3.GetComponent<level2OPbox>().finalVal==0)

        {

            Debug.Log("open");

           i=2;

            door.transform.position= Vector3.Lerp(door.transform.position,openDoor,1000f);

            door2.transform.position= Vector3.Lerp(door2.transform.position,openDoor2,1000f);

            door3.transform.position= Vector3.Lerp(door3.transform.position,openDoor3,1000f);

            door4.transform.position= Vector3.Lerp(door4.transform.position,openDoor4,1000f);

        }

    }


}

and The Screenshot of the Game Object The script is attached to


Comments

  • Tobias
    Options

    I can't read / debug your code, sorry. But to give some insight: You probably want to just store the door's state. PUN can do that in Custom Room Properties (e.g.). Make up a Custom Room Property for a door that you operate and even late joiners will get the current state (only). You don't have to store all door default states.

    You can play animations locally when the state changes.