Unable to get RPC to activate
Options
I'm trying to get a RPC to turn the SetActive to false when the player collides with the object its attached to. I have a simple script on the object and I get all the triggers until the call itself, then nothing...no error message or effect.
Here's my script:
The game runs perfectly until I collide with the object, then the object just moves insteads of turning off. I can confirm the OnCollisionEnter() is working since score goes up and the print mssg appears in the console. Any help is appreciated.
Here's my script:
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; public class DesttroyOnCollide : MonoBehaviourPun { int point = 1; [PunRPC] private void OnCollisionEnter(Collision other) { PhotonView otherPV = other.gameObject.GetComponent<PhotonView>(); print(other.gameObject.name);//for debug purposes { if (other.gameObject.tag == "Player" && otherPV.IsSceneView && otherPV.IsMine) { other.gameObject.GetComponent<PlayerScore>().score = other.gameObject.GetComponent<PlayerScore>().score + point; PhotonView.Get(this).RPC("DestroyPoint", RpcTarget.AllBuffered,null); //PhotonView.Get(this).RPC("DestroyPoint", RpcTarget.OthersBuffered, null);//alternative attempt print("Player contact"); } } } [PunRPC] private void DestroyPoint() { print("player chomp"); this.gameObject.SetActive(false); } }I've tried this both in Unity without the joining a room (with GameManager script turning offline mode on) and joining a room while running a client-host config on the same machine...same results. Both the player and the gameobject this script is attached to have Photon View components, player tag is set right, and I can't think of what else to check.
The game runs perfectly until I collide with the object, then the object just moves insteads of turning off. I can confirm the OnCollisionEnter() is working since score goes up and the print mssg appears in the console. Any help is appreciated.
0
Best Answer
-
OK...very weird but i deleted and retyped the [PunRPC] above the DestroyPoint() and it now works!0
Answers
-
Sorry about the formatting. Here's a better view:
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; public class DesttroyOnCollide : MonoBehaviourPun { int point = 1; [PunRPC] private void OnCollisionEnter(Collision other) { PhotonView otherPV = other.gameObject.GetComponent<PhotonView>(); print(other.gameObject.name); { if (other.gameObject.tag == "Player" && otherPV.IsSceneView && otherPV.IsMine) { other.gameObject.GetComponent<PlayerScore>().score = other.gameObject.GetComponent<PlayerScore>().score + point; //GetComponent<PhotonView>() PhotonView.Get(this).RPC("DestroyPoint", RpcTarget.AllBuffered,null); PhotonView.Get(this).RPC("DestroyPoint", RpcTarget.OthersBuffered, null); print("Player contact"); } } } [PunRPC] private void DestroyPoint() { print("player chomp"); this.gameObject.SetActive(false); } }
0 -
OK...very weird but i deleted and retyped the [PunRPC] above the DestroyPoint() and it now works!0
-
Nevermind, it still doesn't work....0