Hello! I have a PlayerShoot script: This is one of its methods:
[Command] void CmdShoot() { // Create the Bullet from the Bullet Prefab GameObject bullet = Instantiate( bulletPref, bulletSpawn.position, bulletSpawn.rotation); // Add velocity to the bullet bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * 700; //// Spawn the bullet on the Clients NetworkServer.Spawn(bullet); // Destroy the bullet after 2 seconds Destroy(bullet, 2.0f); } The call to this method occurs when you click on the LMB. Everything works fine except for one BUT, the bullet spawn occurs on the server and is transmitted to the client (as I understand it) and when I connect to the server (remotely in another city), then when shooting from the client, the bullet will spawn with a delay after the shot and if I walk (character) the bullet will spawn out of the weapon.
This is an example of how to spawn a bullet while walking to the right to the left. I need to do this: the bullet must spawn on the client and be transmitted to the server. I tried to do this:
void Shoot() { // Create the Bullet from the Bullet Prefab GameObject bullet = Instantiate( bulletPref, bulletSpawn.position, bulletSpawn.rotation); // Add velocity to the bullet bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * 700; //// Spawn the bullet on the Clients // NetworkServer.Spawn(bullet); CmdSpawn(bullet); // Destroy the bullet after 2 seconds Destroy(bullet, 2.0f); } [Command] void CmdSpawn(GameObject bullet) { //Spawn the bullet on the Clients NetworkServer.Spawn(bullet); } But it produces the following error: NullReferenceException: Object reference not set.
Please help to make the bullet spawn on the client and go to the server (its location) as it happens with the player.
PS Many thanks to everyone!
