- Home /
Photon assign objects in scene as player?
In my scene right now I have 2 player objects. What I want to do is when I load the scene with Photon, I want to assign one of the two objects to be my player. However, if I give both objects PhotonView components, they both act like my player and I can control both of them. Is there a way I can set my player to control only one of them, rather than both of them?
Answer by NFMynster · Aug 29, 2016 at 12:12 AM
You gotta use the "PhotonView.IsMine" as explained here Basically just disable the components that "aren't" yours. I would recommend making a script for disabling multiple components. (Audio source, camera, controllers)
A good start would be:
// Disable the components that should only be
// active on the player we control
if (!isLocalPlayer)
{
for (int i = 0; i < componentsToDisable.Length; i++)
{
componentsToDisable[i].enabled = false;
}
}
Oh yeah, the code I wrote is for UNET, you gotta replace !isLocalPlayer with the "Is$$anonymous$$ine" from the PhotonView.