I'm trying to make 2D-multiplayer game with randomly generated map.
Here's some simplified code what I have tried
public class Map : NetworkBehaviour
{
private TilePainter _tilePainter;
[Command]
public void CmdStartGenerating()
{
_tilePainter.PaintSection(section)//section is randomly generated map information
}
}
public class TilePainter : NetworkBehaviour
{
public Tile tile;
private Tilemap _tilemap;
public void PaintSection(Section section)
{
section.Foreach(x=>{
_tilemap.SetTile(x.Vector3(), tile);
})
}
}
Of course I made them have NetworkIdentity and CmdStartGenerating is called by button click.
The problem is that generated tilemap is visible only in host player.
The other client cannot see generated tile map.
In real code, TilePainter also instantiate some prefabs and they are visible to both player.
I have tried making them network spawnable prefabs but didn't work. (with same problem)
Is there any method like NetworkServer.Spawn for tilemap??
I'm new to Unity multiplayer feature so maybe I'm making some stupid mistake...
Thanks for reading my question!
####Edit
Uploading additional code I've tested in test scene.
public class NetTest : NetworkBehaviour
{
public TileRiverMap tileRiverMap;
private SectionGenerator _sectionGenerator =
new SectionGenerator(10, 20, 1f);
public void Test()
{
Debug.Log("hihi");
tileRiverMap.PaintSection(_sectionGenerator.GenerateSection((0, 0)), 5);
}
}
Class below is Player object
public class TestPlayer : NetworkBehaviour
{
private void FixedUpdate()
{
if (isLocalPlayer)
{
if (Input.GetButtonDown("Jump"))
{
CmdTest();
}
}
}
[Command]
private void CmdTest()
{
FindObjectOfType<NetTest>().Test();
}
}
public class TileRiverMap : NetworkBehaviour, IRiverMap
{
public Tile tile;
public GameObject stone;
private Tilemap _tilemap;
......
}
I don't think whole code of TileRiverMap is needed