- Home /
Finding the player who killed you (Multiplayer)
Hi guys, so i have a multiplayer game setup and so far you can shoot and kill your enemies. So the problem is that i am trying to get the name of the player who killed you, as well as send a message to that gameobject to add a score to the players' kill streak. It is not done with raycast, bullets are instantiated and then move forward, if that info helps. So please can anyone please help me, i am using photon unity networking. Thanks guys!
Each bullet should contain an information allowing to identify the shooter (a name / a numeric id / an object reference). Then on hit you can find the killer and send a message or do whatever you like.
Could you maybe help me on how to do this, I have no idea on how to implement this
Without seeing your code, I don't think anyone can guess what to do.
Answer by abhi_360 · May 22, 2015 at 05:45 AM
ok i dont know your code so all of this is a big guess. All your network players if instantiated by Network.Instantiate will have a networkviewid which is unique.
Add a NetworkViewId playerId variable to your Gun In your Gun script which will have a bullet prefab get the playerId from the the parent players NetworkView OnStart() and when instantiating the bullet in your gun script use GameObject bullet = Network.Instantiate(//add your args)
Your bullet script should have a NetworkViewId playerID variable. So after instantiating say bullet.playerId = playerId
//Maintain a List of all players for this to work Now OnHit check the list of players for there NetworkViewId if it matches the bullets playerId then add to his score
Without the actual code this is the best i can help you with
I actually don't need such a complicated method, all I need is to know if the player killed someone to add points to the killstreak
//That was the least complicated solution without your reference code //T_T
Try to find way to tell the bullet like dude your xyz player's bullet don't kill xyz and kill everyone else. So if your bullet knows it belongs to xyz player bullet->damage->Enemy and bullet->score->xyz
//Normally in professional projects these things are accounted for b4 //hand have look at How to make Class Diagrams and prepare one b4 //initiating with your project.$$anonymous$$ultiplayer is a huge topic (like if u //send too much packets to the server the server socket might may fail //as each LAN card has its max data reception speed)
Best of Luck
Your answer

Follow this Question
Related Questions
[PUN2] Problem at pushing the other players 1 Answer
Photon PUN 2 RTS one time information sharing 0 Answers
MMO server side programming 0 Answers
Send Custom Network Message Unity Multiplayer 0 Answers
,Unity Multiplayer - Instantiate prefab 0 Answers