Search code examples
unity-game-enginenetwork-programmingmultiplayerphoton

Unity PhotonView is mine check


I am implementing Photon multiplayer into my game and I have a concern with my method of checking for local player.

Currently, I check for the local player in various spots by using PhotonView.IsMine().

Am I correct in saying that the script is still running for all clients however only the local player runs their instance of the script? For example my movement script is attached to all clients, but I check PhotonView.IsMine() before applying movement to prevent clients from controlling each other.

Does anyone know of any better practices or techniques you use in your projects? I don't think my method is very good and could be made much more efficient and easier to set up.


Solution

  • You can check in the Start method if the instance is yours and simply remove the component (use the Destroy method). If you need some functions that are in this script to run in all of your clients, use them in another script that you won't remove.