In my game inside Unity, I have two scenes setup. One for the main server ( acts like authoritative server ) and the other scene for my client. The game starts once my client connects to the server.
Now I am able to send RPC function calls from my scripts in my client scene to the server but I am not able to do it the other way around.
** Further edit to my code after comments ** *********** This is my client side script attached to GameObject CursorDetection inside Scene2 *****
using UnityEngine;
using System.Collections;
// ON THE CLIENT SIDE
public class CursorDetectionScript : MonoBehaviour {
private bool hasGameStarted = false;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
networkView.RPC("mouseDown", RPCMode.Server,true);
}
}
[RPC]
public void mouseDown(bool isMouseDown)
{
}
}
**** On the server side script inside scene1 *******
private void OnPlayerConnected(NetworkPlayer player)
{
Debug.Log(" PLAYER CONNECTED " +player);
networkView.RPC("AddNetworkPlayer", RPCMode.AllBuffered, player);
}
[RPC]
public void AddNetworkPlayer(NetworkPlayer player)
{
playersList.Add(player);
Debug.Log(" FIRST PLAYER IS " + playersList[0]);
}
if(startGame)
{
networkView.RPC("SendMessageToClient1", RPCMode.AllBuffered, playersList[0]);
}
[RPC]
public void mouseDown(bool isMouseDown, NetworkMessageInfo sender)
{
isMouseDown = true;
Debug.Log("CAN PLACE PANELS NOW" + " VIEW IS " + sender.sender.guid);
}
**** back on the client side script inside scene2 I called the SendMessageToClient1 function call *******
[RPC]
public void SendMessageToClient1()
{
Debug.Log(" INSIDE CLIENT 1 ");
}