Help with RPC

Options
Hello how can i make this in my script since photon does not automatically sync transform parenting in hierarchy, this means i have to do it per RPC.
My script:
using UnityEngine;
public class playerplatform : MonoBehaviour {
    public GameObject platform;
    void OnTriggerEnter(Collider other) {
        if (other.gameObject.CompareTag("Player")) {
            other.transform.parent = platform.transform;
        }
    }
    void OnTriggerExit(Collider other) {
        if (other.gameObject.CompareTag("Player")) {
            other.transform.parent = null;
        }
    }
}

Comments

  • Hello?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited May 2020
    Options
    the code snippets in this post are from the top of my head and not tested.

    the GameObject that has tag Player needs to have a PhotonView
    using UnityEngine;
    public class playerplatform : MonoBehaviour {
        public GameObject platform;
        void OnTriggerEnter(Collider other) {
            if (other.gameObject.CompareTag("Player")) {
                PhotonView photonView = other.gameObject.GetComponent<PhotonView>();
                if (!photonView) {
                } else if (photonView == null) { 
                } else if (photonView.IsMine) {
                    photonView.RPC("SetPlatformAsParent", RpcTarget.Others);
                    other.transform.parent = platform.transform;  // do it locally
                 }
            }
        }
        void OnTriggerExit(Collider other) {
            if (other.gameObject.CompareTag("Player")) {
                PhotonView photonView = other.gameObject.GetComponent<PhotonView>();
                if (!photonView) {
                } else if (photonView == null) { 
                } else if (photonView.IsMine) {
                    photonView.RPC("SetNullAsParent", RpcTarget.Other);
                    other.transform.parent = null; // do it locally
                 }
            }
        }
    }
    

    implement RPCs on script attached to the same GameObject as PhotonView and that has reference to the platform.
    public GameObject platform;
    [PunRPC]
    private void SetPlatformAsParent()
    {
        this.transform.parent = platform.transform;
    }
    [PunRPC]
    private void SetPlatformAsParent()
    {
        this.transform.parent = null;
    }
    
  • FedericoDeveloper
    edited May 2020
    Options
    Thanks @JohnTube will test
  • FedericoDeveloper
    edited May 2020
    Options
    Hi i used your code but i'm getting this error.
    error CS0117: 'RpcTarget' does not contain a definition for 'Other'
    
    Edit: fixed
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Others*
  • @JohnTube Doesn't work, when local player gets in they are in the helicopter they still get sent to that position even tho the remote of them selves isnt in the hierachy the will still get send there no matter what
  • @JohnTube By the way, I'm using photon transform view classic
  • @JohnTube using photon transform view fixed it, the issue now is for the trigger that does animator.play because it doesnt sync, the script:
    using UnityEngine;
    using Photon.Pun;
    public class coolhelicopter : MonoBehaviourPunCallbacks {
        public Animator thingy;
        void OnTriggerEnter(Collider other) {
            if (other.gameObject.CompareTag("Player")) {
                thingy.Play("test");
            }
        }
    
        void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
            if(stream.IsWriting) {
                stream.SendNext(thingy);
            }
            else {
                thingy = (Animator)stream.ReceiveNext();
            }
        }
    }
    
  • GreenEclipse
    edited May 2020
    Options
    Hey @FedericoDeveloper :)

    If I'm not mistaken for animations you will need to add a Photon Animator View to the gameobject that has the component Animator. Then when you will call your animation it will be played.
  • @GreenEclipse I did put a photon animator view but the thing is that it still wont work https://imgur.com/a/xzw6Kve