- Home /
Unity Photon Networking call script on object
Hello, I am working with Unity Photon Networking while beginning to make multiplayer games. I chose this because it is free and because I didn't like the complicated stuff with Unity standard networking. Also because it has some advantages which I'm not going to list. My problem is this:
When 1 shoot another player with raycasting, his object calls a script which makes it loose health. The problem is that this only happens on my computer. The second object is actually healthy.
How can I force the second object to call this script on himself?
Let's assume that the object's name is 'player' without quotes and the script is GetComponent().die() as I call it using my object.
Answer by CodeElemental · Dec 23, 2014 at 01:06 PM
PhotonView photonView; // Initialize this componnent of the 'networked' object
public void BulletHit()
{
// .. if conditions are met (ex. enemy is hit)
{
photonView.RPC("TakeDamage", PhotonTargets.All, enemyHit.name);
}
}
[RPC]
public void TakeDamage(string name)
{
// If my name is the same as the one that is supposed to take damage , take damage , otherwise nothing.
}
There are optimizations to this but it depends on your networking architecture. (For example only the server gets the message, checks which of the players is hit and re-sends the rpc only to that player)
Your answer
Follow this Question
Related Questions
How to change offline to online mode in photon unity network 1 Answer
How to control photon server while getting disconnect automatic 0 Answers
Cloud recognition in Vuforia 0 Answers
Particle System Delay 0 Answers
Ground and Object Jumping problem 1 Answer