Multiple Players - 3D Shared Parent Object (Changing Color)

Options
Hello PUN Experts!

I am hoping to use PUN for a small project I am working on, was hoping to have a game object set-up with multiple
child components (Lets for instance say a box with multiple cubes in it.).

Is there a way to have multiple people enter a server and take control of this "shared game object" to specifically change the color of the child components?

Just as an example, lets say two people enter the same server, and both have access to this box of cubes. Both the players are each given a different color and should be able to change the color of the cubes, overwriting the cube with their color when they click on it.

Have seen some similar questions when I google search, but they all seem to be about changing the position rather than something simple like changing the color of a stationary object.

Thanks in advance! Greatly appreciate any help to steer me in the right direction.

Answers

  • PB_Xander
    Options
    The simpliest way to do what you want without any conflicts is just inherit shared object script from MonoBehaviourPunCallbacks, then override OnOwnershipRequest() and OnOwnershipTransfered() methods and do your job inside. Do not forget to actually call photonView.RequestOwnership (say, inside OnMouseDown) and to set PhotonView's ownership transfer to Request or Takeover (based on your logic and desired behavior). The color change could be implemented via limited set of colors by sending the index inside OnPhotonSerializeView, or using RPC method if you wish to let player to choose any color.