- Home /
please help multiplayer question(photon).
help .. i made an assault shield and i put photonview on it but when i start my game twice on the second screen the shield doesnt show up on the chracter but from the chracter itself i van see it.
my variables:
var uses int = 1;
var shield : GameObject;
.................................
if(Input.GetKey(KeyCode.V)&&uses=1){
shield.SetActive(true);
WaitForSeconds(10){
shield.SetActive(false);
}
}
Build the game run it, then in the editor, dont move any of the players and activate the shield in the built version.
Now look for the shield in the editor:
is it somewhere wrong? This is usually a problem while parenting the gameobjects
does it follow the player? You may have not set the transform of the shield in the photon view component, or you are instantiating the shield at runtime (Ill explain further if this is the case)
doesn't exists at all? this is more complex a video showing doing what I explained, the shield component in the editor etc may help
Answer by Tumtable · Jan 03, 2015 at 01:36 PM
I guess that's because the SetActive() method only works at the local game. If you want to activate or deactivate the shield using SetActive(), you will need to call a RPC function on all the clients to activate your shield on their games too. Like that:
var uses int = 1;
var shield : GameObject;
.................................
if(Input.GetKey(KeyCode.V)&&uses=1){
networkView.RPC("activateShield", RPCMode.AllBuffered, true);
WaitForSeconds(10){
networkView.RPC("activateShield", RPCMode.AllBuffered, false);
}
}
@RPC
function activateShield(active:bool) {
shield.SetActive(active);
}
Of course that's a lot of ways to do that, you can also call a RPC method that controls the shield on the other clients game. =]