- Home /
PhotonView with id has no method marked with PunRPC
I have this code to send info:
using UnityEngine;
using System.Collections;
public class SendAttackInfo : MonoBehaviour {
public int damage = 100;
// Use this for initialization
void Start () {
}
void Update () {
bool RMB = Input.GetMouseButtonDown (1);
if (RMB) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//&& hit.transform.tag == "Player" && hit.collider.name != this.gameObject.name
if (Physics.Raycast(ray, out hit)){
//float dist = Vector3.Distance(hit.transform.position, this.transform.position);
//if(dist <= 2.0f) {
PhotonView pv = PhotonView.Get(this);
if (pv.isMine) {
hit.collider.gameObject.GetComponent<PhotonView>().RPC("ApplyDamage", PhotonTargets.All);
}
}
//}
}
}
}
And this to recieve:
[PunRPC]
void ApplyDamage(){
curHealth -= 50;
Debug.Log("hit player " + curHealth);
}
When I try them I get this error:
PhotonView with ID 1002 has no method "ApplyDamage" marked with the [PunRPC](C#) or @PunRPC(JS) property! Args:
Please help!
Answer by tobiass · Sep 15, 2015 at 04:24 PM
The ApplyDamage method has to be in a script that's on the same GO as the PhotonView. This is maybe not the case?
I can't add PhotonView to each object or is it ok to having too many objects which has PhotonView component?
I have empty Building gameObject. In it I have 3 child objects. $$anonymous$$y empty Building has PhotonView component. I'm instantiating Building object like this:
GameObject Building1 = (GameObject)PhotonNetwork.InstantiateSceneObject ("Building1", gameObject.transform.position, Quaternion.identity, 0, null);
how can I sync destruction of child objects.
I made like this but I'm having same error.
void OnCollisionEnter (Collision col)
{
if (col.gameObject.tag == "Bullet")
{
hitPoints = hitPoints - BulletScript.damage;
if (hitPoints <= 0)
{
GetComponentInParent<PhotonView> ().RPC ("DestroyColone", PhotonTargets.All, hitPoints);
}
}
}
[PunRPC]
void DestroyColone ()
{
Instantiate (broken, transform.position, transform.rotation);
Instantiate (dustFX, transform.position, transform.rotation);
Destroy (this.gameObject);
}
Answer by yigites · Dec 12, 2015 at 04:46 AM
@geotsak, @tobiass is right and addition to this , I had the same issue. When you made any changes in RPC functions in your code or made changes in your prefab , you have to drag your prefab to scene and press apply in inspector, than you can delete it from scene. It resolves this error every time for me.
Your answer
Follow this Question
Related Questions
Destroying entire parent object on one client but on the other destroying just the child. 1 Answer
How to make script work for all players Unity Photon? 1 Answer
Unity Collision Doesn't Work when Two Players Instantiated 1 Answer
Instantiating scene objects in Photon Multiplayer. 0 Answers
Why do other players have stuttering / laggy movement in Photon? 0 Answers