- Home /
Question by
zugfaehn · Oct 23, 2016 at 04:53 PM ·
c#networkingclient-server
Networking: Client-spawned Objects do not appear on Server
Hey,
I got a Method "Rpc_Shoot()", that is called when pressing MouseButton0. It spawns projectiles. I want this to work in a multiplayer scenario with a Host and a connected Client. At the Moment both players can shoot the projectiles, but only the projectiles shot by the host appear for the other player. When the other player (Client) shoots a projectile, this wont appear for the Host (or even on the Server I guess?). Heres the Code:
//shoot
if (Input.GetKeyDown(KeyCode.Mouse0) || Input.GetKey(KeyCode.Mouse0)) {
Rpc_Shoot();
}
//this is the important part of the Rpc_Shoot() method
[RPC]
public void Rpc_Shoot() {
GameObject proj = (GameObject) Instantiate(projectile,firePoint.position,firePoint.rotation);
NetworkServer.Spawn(proj);
}
On the Client side the method gets entered. The only thing that doesnt work is, that the client cant spawn his projectiles on the server. The projectile has a NetworkIdentity attached and is registered in the NetworkManager.
Comment