So, I was trying to add a server-sided script, and I don’t really know how to fix it.
I get the error when I try it:
RPC method ‘EnableObjectRPC()’ not found on object with PhotonView 1. Implement as non-static. Apply [PunRPC]. Components on children are not found. Return type must be void or
IEnumerator
(if you enableRunRpcCoroutines
). RPCs are a one-way message.
If anybody knows how to fix this, any help would be greatly appreciated.
Here’s the script:
using UnityEngine;
using Photon.Pun;
public class EnableServersided : MonoBehaviourPun
{
public GameObject objectToEnable;
public PhotonView photonView;
void OnTriggerEnter(Collider other)
{
if (photonView.IsMine && other.CompareTag("HandTag"))
{
Debug.Log("Trigger entered by local player with HandTag. Calling EnableObjectRPC...");
photonView.RPC("EnableObjectRPC", RpcTarget.All);
}
}
[PunRPC]
private void EnableObjectRPC()
{
Debug.Log("RPC received. Enabling object...");
if (objectToEnable != null)
{
objectToEnable.SetActive(true);
Debug.Log("Object enabled for all players.");
}
else
{
Debug.LogError("objectToEnable is not assigned!");
}
}
}