Door script not updating for all players

I'm making a game with PUN2 and and most everything is working but I have a automatic door that is causing me some problems. The Animator on the door is working player side for all characters, but it only plays across the server when whoever is hosting the walks to the door:



But if the player who is not hosting walks into the door it will play for her but not across the server to all players:

I'm not that good of a scripter (I mostly do 3d work) and I have hit a wall. here is the script so you can see what's going on:

using UnityEngine;
using System.Collections;
using Photon.Pun;

[RequireComponent(typeof(PhotonView))]
[RequireComponent(typeof(PhotonAnimatorView))]


public class Animation_door : MonoBehaviourPunCallbacks
{

Animator anim;
public AudioClip doorOpenClip;
public AudioClip doorCloseClip;

PhotonView view;
Animator animator;


void Start()
{
anim = GetComponent();
}

[PunRPC]

void OnTriggerEnter(Collider other) {
if(other.GetComponent().tag=="Player")
{
anim.SetBool("Open",true);
GetComponent().clip = doorOpenClip;
GetComponent().Play();
}
}

[PunRPC]

void OnTriggerExit(Collider other) {
if(other.GetComponent().tag=="Player")
{
anim.SetBool("Open",false);
GetComponent().clip = doorCloseClip;
GetComponent().Play();
}
}
}

Comments

  • Avalin
    Avalin
    edited October 2018
    Hi there, I'm also quite new to photon mind you, but I was wondering how you call your RPCs? You should use the syntax photonView.RPC("methodName", RpcTarget.All, "yourParameters")
    Whereas target defines whether other clients see what goes on from your client or not. Also I'm pretty sure RPCs can only take primitive parameters like strings and ints, and not a Collider. I personally use their ViewID to specify if it's the right object, and that works fine

    I would suggest you make some new functions and give them the PunRPC, and call those new functions from the trigger methods with the syntax I wrote above, instead of sending the OnTrigger methods directly. I think that might work.

    Hope this helps a bit^^
  • Here is the working script:

    using UnityEngine;
    using System.Collections;
    using Photon.Pun;

    [RequireComponent(typeof(PhotonView))]
    [RequireComponent(typeof(PhotonAnimatorView))]

    public class Animation_door : MonoBehaviourPun
    {
    //PhotonView photonView = PhotonView.Get(this);
    public bool enter = false;

    Animator anim;
    public AudioClip doorOpenClip;
    public AudioClip doorCloseClip;


    void Start()
    {
    anim = GetComponent();
    }

    void OnTriggerEnter(Collider other)
    {
    if (other.gameObject.tag == "Player")
    {
    photonView.RPC("openDoor", RpcTarget.All, null);
    }
    }

    void OnTriggerExit(Collider other)
    {
    if (other.gameObject.tag == "Player")
    {
    photonView.RPC("closeDoor", RpcTarget.All, null);
    }
    }

    [PunRPC]
    void closeDoor()
    {
    //Debug.Log("Trigger Exit");
    (enter) = false;

    anim.SetBool("Open",false);
    GetComponent().clip = doorCloseClip;
    GetComponent().Play();
    }

    [PunRPC]
    void openDoor()
    {
    //Debug.Log("Trigger Enter");
    (enter) = true;

    anim.SetBool("Open",true);
    GetComponent().clip = doorOpenClip;
    GetComponent().Play();

    }


    }