- Home /
MultiPlayer - NetworkPlayer Event
Hello,
I'm working on the bits of my network game of when someone quits or leaves. Basically, the game is a 'capture the flag' type game, and I want to call a function when the player has the flag, and then quits... So the flag is 'dropped', instead of being destroyed with the player.
The function is attached to the actual character, and I'm struggling to talk to it.
So, when someone leaves, this function is called:
function OnPlayerDisconnected (player : NetworkPlayer){
This is on a game object on my root. I need to somehow use the 'player' as a reference to find the 'character' to then call the function attached to him.
The function is an RPC and is called DropFlag, and is on a script called 'HealthSystem', and is attached to my character:
networkView.RPC("DropFlag", RPCMode.AllBuffered, player.viewID);
So, what I really need to do is something like this:
var character = player.FindObject("Player");
var health = character.GetComponent(HealthSystem);
health.networkView.RPC("DropFlag", RPCMode.AllBuffered, player.viewID);
This 'DropFlag' works, its also called when you kill the player with the flag... He drops it, and spawns somewhere else, without the flag.
Not sure I understood you properly. You're saying that it works fine when the player is killed but not when the player disconnects? It could be that the game object/component has already been destroyed? Could you try calling it from the OnDestroy if the player has the flag?
I second ThePunisher. At some point, if the game object is getting destroyed, then at some point OnDestroy will get called. That will make sure 'DropFlag' gets called.
ThePunisher, why didn't you put that in an answer?
Answer by ThePunisher · Jul 05, 2012 at 04:43 PM
It could be that the game object/component has already been destroyed? Could you try calling it from the OnDestroy if the player has the flag?
Your answer
Follow this Question
Related Questions
Get the ID/name of the player that joined the game. 1 Answer
Network Instantiate with wrong owner. 2 Answers
help on synchronizing newtorked views... 0 Answers
Sending info to/from different networkViews 1 Answer
Multiplayer Animating 2 Answers