How to synchronize GameObjects in scene on change (not transform or rotate)?
Options
Hey!
I'm new to Unity and Photon and I am trying to make selected GameObjects in the scene glow when ever they are clicked on with the mouse. Currently I have the glow effect as a child-GameObject of the objects that I want to glow and when they are hit by Raycast the effect object is enabled and later disabled. This works for each individual player in the game but the glow doesn't synchronize between players. Any idea on how to implement this?
I'm new to Unity and Photon and I am trying to make selected GameObjects in the scene glow when ever they are clicked on with the mouse. Currently I have the glow effect as a child-GameObject of the objects that I want to glow and when they are hit by Raycast the effect object is enabled and later disabled. This works for each individual player in the game but the glow doesn't synchronize between players. Any idea on how to implement this?
0
Best Answer
-
You could use a RPC to send the function that makes the glow appear to all players!
They are like normal class methods but you can call them for all all players etc.
So give the parent object a view and don't forget to extend MonoBehaviourPun.
Roughly the code:
public class GameObjectThatShouldGlow : MonoBehaviourPun
{
void makeMeGlow()
{
this.photonView.RPC("makeMeGlowImpl", RpcTarget.All, furtherParameters, .... )
}
void makeMeGlowImpl()
{
ActivateLight()
}
}
If you want mid game join I advise you to use serialization:
class GameObjectThatShouldGlow : MonoBehaviourPun, IPunObservable
void Update()
{
bool bLightIsOn = false;
if(bLightIsOn)
{
ActivateLight()
}
}
void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.sendNext(bLightIsOn)
}
else
{
bLightIsOn = (bool)stream.receiveNext();
}
}
(The code is propably not going to work, it's just to give you a idea of the process)
Also attaching a view to each object is a bad idea if you have many as the limit of views is 1000, so you might want to make the RPC in your player object, give each GameObject a Id and then send that as parameter.
Greetings.5
Answers
-
You could use a RPC to send the function that makes the glow appear to all players!
They are like normal class methods but you can call them for all all players etc.
So give the parent object a view and don't forget to extend MonoBehaviourPun.
Roughly the code:
public class GameObjectThatShouldGlow : MonoBehaviourPun
{
void makeMeGlow()
{
this.photonView.RPC("makeMeGlowImpl", RpcTarget.All, furtherParameters, .... )
}
void makeMeGlowImpl()
{
ActivateLight()
}
}
If you want mid game join I advise you to use serialization:
class GameObjectThatShouldGlow : MonoBehaviourPun, IPunObservable
void Update()
{
bool bLightIsOn = false;
if(bLightIsOn)
{
ActivateLight()
}
}
void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.sendNext(bLightIsOn)
}
else
{
bLightIsOn = (bool)stream.receiveNext();
}
}
(The code is propably not going to work, it's just to give you a idea of the process)
Also attaching a view to each object is a bad idea if you have many as the limit of views is 1000, so you might want to make the RPC in your player object, give each GameObject a Id and then send that as parameter.
Greetings.5 -
Thank you ! I had already managed to make it work with RPC calls exactly like you described. Will keep in mind to give each object separate ID if they will get to many0
-
Great! Also, if you should ever get that "Received OnSerialization for view ID xxxx. We have no such PhotonView..." error on mid game join, please hit me up... can't find the source...0