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:
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; } } }
0
Comments
-
Hello?0
-
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 PhotonViewusing 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; }
0 -
Thanks @JohnTube will test0
-
Hi i used your code but i'm getting this error.
error CS0117: 'RpcTarget' does not contain a definition for 'Other'
Edit: fixed0 -
Others*0
-
@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 what0
-
@JohnTube By the way, I'm using photon transform view classic0
-
@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(); } } }
0 -
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.0 -
@GreenEclipse I did put a photon animator view but the thing is that it still wont work https://imgur.com/a/xzw6Kve0