I've been struggling with this for a day or two now. For some reason NetworkServer.Spawn() isn't seeming to work. To my understanding, NetworkServer.Spawn() can be called from a client to spawn and object on the server, and from the server, the object is spawned on all of the clients. Currently, when a client shoots, it only appears on that client, (NOT on the server) and when the host shoots, the projectile is spawned on the host and the clients.
There is a using Mirror tag at the top of the code and the script derives from Networkbehaviour. This piece of code below is called on the client:
void Shoot()
{
//Spawn porjectile on local machine
GameObject shot = Instantiate(projectile) as GameObject;
//Set shot projectile position
shot.transform.position = projectilePoint.position;
shot.transform.rotation = transform.rotation;
//Set projectile component of the shot projectile
Projectile shotProjectile = shot.GetComponent<Projectile>();
//Set properties of shot projectile
shotProjectile.damage = damage;
shotProjectile.direction = projectilePoint.position - transform.position;
shotProjectile.speed = projectileTravelSpeed;
shotProjectile.team = team;
shotProjectile.shotBy = gameObject;
NetworkServer.Spawn(shot);
}
Does anyone have an idea of why the projectile isn't spawned on the server from a client? A code example (in c#) would also be very helpful.