- Home /
Question about Network and NetworkViewID
Hello,
I am trying to make a reactionary-game, like whack-a-mole. The clients send an RPC to the server which does Network.Destroy() on the object and then sends an RPC back to the client who sent the RPC in the first place, and only him.
It works fine unless two clients presses pretty much the same time; then both gets an RPC back, which I do not want - only the fastest sender should get an RPC back.
Here's what the server gets from the client when the client clicks a mole:
[RPC]
void OnClientKillMole(NetworkViewID mole,NetworkMessageInfo info)
{
try
{
Network.RemoveRPCs(mole);
Network.Destroy(mole);
networkView.RPC("OnClientKillMoleSuccess",info.sender);
}
catch (UnityException e) { Debug.Log(e); }
}
How do I make this NetworkViewID 'marked' or something? How can I check if I have already destroyed it with Network.Destroy()?
Answer by Elric · Jan 22, 2013 at 02:48 AM
Maybe you should make an array of killed moles? Something like that:
Array killedMoles = new Array();
[RPC]
void OnClientKillMole(NetworkViewID mole,NetworkMessageInfo info)
{
try
{
for(NetworkViewID moleID in killedMoles){
if(moleID == mole) return;
}
Network.RemoveRPCs(mole);
Network.Destroy(mole);
networkView.RPC("OnClientKillMoleSuccess",info.sender);
killedMoles.Add(mole);
}
catch (UnityException e) { Debug.Log(e); }
}
Your answer
Follow this Question
Related Questions
Question about Network.Destroy 0 Answers
Sending a gameobject over network with RPC? 2 Answers
Network - Client still in Network.Connections after disconnect 2 Answers
Run several unity clients at once in windows? 0 Answers
Unity Multiplayer Design. Is it complicated to implement and learn? 1 Answer