unity3d - Simple Unity5 LAN game, server updating clients are not -
i making simple lan game bearings in unity networking. supposed when player clicks on square in grid, changes blue. issue when lan host clicks on square, updates locally , doesn't update clients. when client clicks on square, updates locally , lan host gets updated, other clients not updated. of grid pieces have network identity attached them
any ideas?
heres code:
using unityengine; using system.collections; using unityengine.networking; public class player_paint : networkbehaviour { [syncvar]gameobject syncgridpiece; gameobject gridpiece; void update () { paint(); transmitgridcolours(); } void paint(){ if(islocalplayer && input.getmousebuttondown(0)){ raycasthit2d hit = physics2d.raycast(camera.main.screentoworldpoint(input.mouseposition), vector2.zero); if(hit.collider != null){ print(gameobject.find (hit.transform.name)); gridpiece = hit.collider.transform.gameobject; gridpiece.getcomponent<spriterenderer>().color = color.blue; } } } [command] void cmdprovidegridcolourtoserver(gameobject gridpiece){ if(gridpiece){ syncgridpiece = gridpiece; syncgridpiece.getcomponent<spriterenderer>().color = color.blue; } } [client] void transmitgridcolours(){ if(islocalplayer){ cmdprovidegridcolourtoserver(gridpiece); } } }
you need add hook syncgridpiece syncvar. in hook function set color blue, did in command. hook called on remote players.
also don't think can use gameoject syncvar. need send it's id.
[syncvar(hook=updategridpiece)] int syncgridpiece
maybe rpc more adapted want do. understand syncgridpiece square shouldn't pass updates in same message. send x players clicked x square rpc.
look @ damage example : https://docs.unity3d.com/manual/unetactions.html
Comments
Post a Comment