how to fix - RPC method 'ReduceHEalth(Single)' not found on object with PhotonView 2001. Implement a

Options

hi , i am new to Photon and i am using PUN 2 in my project . this is my first multiplayer project

what i am trying to do is , i have a player and the player can shoot bullets , on player there is a health script that takes care of player health , now bullets are using triggers to detect collisions and when a bullet hits another player , i want to subtract the heath of another player by using a rpc in health script attached to the player through my bullet script . and how can i destroy bullets through rpc

i am getting following error

RPC method 'ReduceHEalth(Single)' not found on object with PhotonView 2001. Implement as non-static. Apply [PunRPC]. Components on children are not found. Return type must be void or IEnumerator (if you enable RunRpcCoroutines). RPCs are a one-way message.

above one in health script


RPC method 'destoryObject()' not found on object with PhotonView 1002. Implement as non-static. Apply [PunRPC]. Components on children are not found. Return type must be void or IEnumerator (if you enable RunRpcCoroutines). RPCs are a one-way message.


this one when i try to destroy bullets after collision



here are my scripts


health script -


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

using Photon.Pun;

using Photon.Realtime;

public class Health : MonoBehaviourPunCallbacks

{

  public Slider slider;


  [PunRPC]

  protected virtual void ReduceHEalth(float amount)

  {

    modifyHEalth(amount);

  }

  void modifyHEalth(float amount)

  {

    if (photonView.IsMine)

    {

      slider.value -= amount;

    }

    else

    {

      slider.value -= amount;

    }

  }

}


bullet script -

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Photon.Pun;

using Photon.Realtime;

public class bulletGame : MonoBehaviourPunCallbacks

{

  public bool moveDir = false;

  public float moveSpeed = 5f;

  public float destoryTime;

  public PhotonView View;


  public float bulletDamage;


  private void Awake()

  {

    StartCoroutine(DestoryByTime());

  }

  // Start is called before the first frame update

  IEnumerator DestoryByTime()

  {

    yield return new WaitForSeconds(destoryTime);

    View.RPC("destoryObject", RpcTarget.AllBuffered);


  }


  public void changeDir()

  {

    View.RPC("ChangeDir_Left", RpcTarget.AllBuffered);

  }


  [PunRPC]

  protected virtual void ChangeDir_Left()

  {

    moveDir = true;

  }

  protected virtual void destoryObject()

  {

    Destroy(gameObject);

  }

  private void Update()

  {

    if (!moveDir)

    {

      transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);

    }

    else

    {

      transform.Translate(Vector2.left * moveSpeed * Time.deltaTime);


    }

  }



  private void OnTriggerEnter2D(Collider2D collision)

  {

    if (!photonView.IsMine)

    {

      return;

    }

    PhotonView target = collision.gameObject.GetComponent<PhotonView>();

    if(target!=null &&(!target.IsMine || target.IsSceneView))

    {

      if(target.tag == "Player")

      {

        target.RPC("ReduceHEalth", RpcTarget.AllBuffered, bulletDamage);

      }

      View.RPC("destoryObject", RpcTarget.AllBuffered);

    }

  }


}

thanks for understanding my problem . pls help me out with this

Best Answer

  • Theplayer
    Theplayer
    Answer ✓
    Options

    update : i figured it out myself , for health one . i had attached the script to a child , attaching it to the object which has photon view fixed it and in destroy one I have just written [punRPC] at the very top of the function , that fixes it

Answers

  • Theplayer
    Theplayer
    Answer ✓
    Options

    update : i figured it out myself , for health one . i had attached the script to a child , attaching it to the object which has photon view fixed it and in destroy one I have just written [punRPC] at the very top of the function , that fixes it