How can I apply damage to my player character? And sync value across players

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How can I apply damage to my player character? And sync value across players

Supran
2020-07-28 13:27:03

I am trying to develop a small multiplayer game. I have a bomb script and every time player hits the bomb button, a bomb is instantiated and exploded after the timer is up. I applied a overlapping sphear to get players in effecting area.. And the players in the area are getting the bombs explosion effect as in getting force from explosion. All works fine expect my damage script. Once a player is damaged all players get that damage. I tried making health an observable component. But all coming up with errors.

How would you approach this problem

Comments

Judgecrome
2021-01-01 10:28:08

PhotonView pht = collision.gameObject.getComponent();
pht.RPC("TakeDamage",RpcTarget.AllBuffered,25);

[PunRPC]
void TakeDamage(int damage)
{
health-=damage;
}

you can do this like that

S_Oliver
2021-01-01 19:54:26

Take a look at this Example.
https://github.com/SradnickDev/Photon-Misc#basic-health--shooting

Back to top