Hello! I’ve been trying to solve this issues for couple days but haven’t had success so far.
I have a script, it is attached to the Player prefab. The Player prefab, in its turn, has a Network Object component and is set as the Player prefab in Network manager.
When I start as a host (NetworkManager.Singleton.StartHost() everything works, but if I connect as a client (NetworkManager.Singleton.StartCleint() the ServerRpc method doesn’t work on Client.
Please find the script below:
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
public class TestingServerRpc : NetworkBehaviour
{
void Update()
{
if (!IsOwner)
return;
if (Input.GetMouseButtonDown(0))
{
DoStuffServerRpc();
}
}
[ServerRpc(RequireOwnership = false)]
public void DoStuffServerRpc()
{
Debug.Log("It works!");
}
}
Thank you!