1
\$\begingroup\$

Good day.

I'm developing my first simple game, a racing car, using Unity and Photon. In my game there are a function that generate random Bonus on random position each (for instance) 5 seconds.

The problem is that if I use RPC, each Peer connected generate a bonus each 5 seconds and send that bonus on other client connected . Results: if i have 5 clients, each clients generate 1 bonus each 5 seconds resulting in 25 bonus each 5 seconds.

So, i would like that ONLY the server generate bonus and send this bonus to each clients.

In short: i don't know how to 'tell' unity and photon "If i am the server run this function, otherwise not"

if (i am server )
   generate bonus
   instantieBonus on clients
}

Thanks

\$\endgroup\$
1
\$\begingroup\$

Use :

if (PhotonNetwork.isMasterClient){
                generate bounds
                run RPC
   }

master client is the first player who joined the room .

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.