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.
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 theRPC_playAnim
the error is referring to!Each method (or in general member) has and requires its own attribute(s).
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.
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 sameGameObject
as thePhotonView
otherwise the receiving client has no chance to find the according component.