0
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayAnimation : MonoBehaviour
{
    [SerializeField] private Animator animator;
    [SerializeField] private string nuke = "nuke";
    public AudioSource nukeSound;

    private PhotonView PV;

    private void Update()
    {
        PV = GetScript.pView;
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Hand"))
        {
            if (other.CompareTag("Hand"))
                PV.RPC("RPC_playAnim", RpcTarget.AllBuffered);
                PV.RPC("RPC_sound", RpcTarget.AllBuffered);
            }
        }
    }

    [PunRPC]
    void RPC_sound()
    {
        nukeSound.Play();
    }

    void RPC_playAnim()
    {
        animator.Play(nuke, 0, 0.0f);
    }
}

That is my script and the error

I tried messing around with the photon views with the rpc's and nothing seems to work,

I even tried testing different photon views but it didn't help if someone could help it would be very appreiciated.

derHugo
  • 83,094
  • 9
  • 75
  • 115

1 Answers1

0

As the error is telling you, your method needs to have the attribute [PunRPC].

You have it only on the RPC_play method but not on the RPC_playAnim the error is referring to!

Each method (or in general member) has and requires its own attribute(s).

[PunRPC]
void RPC_sound()
{
    nukeSound.Play();
}

[PunRPC]
void RPC_playAnim()
{
    animator.Play(nuke, 0, 0.0f);
}

What happens is basically on compile time photon goes through all types and checks if there are any methods attributed with [PunRPC] and if so assigns bakes this method into a dictionary so later via network it just passes on the according key and can thereby find the method on receiver side.

Btw in general to avoid typos I personally prefer to not hard code the names but rather use e.g.

PV.RPC(nameof(RPC_playAnim), RpcTarget.AllBuffered);

Further it could also be that this component is not attached to the same object as GetScript.pView which is the other half of the error message.

The component using PhotonRPC needs to be actually attached to the same GameObject as the PhotonView otherwise the receiving client has no chance to find the according component.

derHugo
  • 83,094
  • 9
  • 75
  • 115
  • I did that but now it's giving me the "RPC method (on both rpc methods) not found on object with photonView 1001. 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." are you able to help me with that? – Alexander Martin Feb 07 '23 at 21:38
  • Well that sounds like this component is not attached to the SE object as `GetScript.pView` ..? – derHugo Feb 08 '23 at 07:42
  • I fixed it all I had to do was add a photonview to the button – Alexander Martin Feb 08 '23 at 23:21