Question by
Topsu · Nov 09, 2017 at 06:32 PM ·
networkingmultiplayer-networkingspawning problems
Spawned item before client joins not visible
If my client joins after weapon has been spawned to other player the client won't see the weapon. I'm also trying to have the weapon as children of the player object
Here is my code:
private void GetWeapon()
{
Debug.Log("weapon!");
GameObject oldWeapon = gameObject.FindChildrenWithTag("Weapon");
GameObject weapon = oldWeapon;
Destroy(oldWeapon);
int index = 0;
while (weapon == oldWeapon)
{
index = Random.Range(0, gameController.weaponList.Length);
weapon = gameController.GetWeapon(index);
}
Debug.Log(weapon.name);
GameObject spawnWeapon = Instantiate(weapon, gameObject.transform);
CmdSpawn(index);
}
[Command]
private void CmdSpawn(int index)
{
GameObject weapon = gameController.GetWeapon(index);
GameObject clone = Instantiate(weapon, gameObject.transform);
}
Comment