Question by
Wykuh · Jan 07, 2017 at 04:37 PM ·
networkingmultiplayer2d-platformerlight
Problem turning off Lights in a Multiplayer 2D game
Hello! I'm Making a multiplayer 2D top down Game where the players have a lantern which they can turn on and off. But the light is not updated on the 2nd Client.
So what I have is; A player prefab with a point light attached as child. the player itself has a script "PlayerController" which looks like this;
void Update()
{
if (!isLocalPlayer)
{
return;
}
if (Input.GetKeyDown(KeyCode.E))
{
CmdLight();
}
}
[Command]
void CmdLight()
{
if (lightOn == true)
{
lightOn = false;
GetComponentInChildren<Light>().intensity = 0f;
Debug.Log("Light OFF");
}
else if (lightOn == false)
{
lightOn = true;
GetComponentInChildren<Light>().intensity = 2.62f;
Debug.Log("Light ON");
}
}
Comment