Problems with camera following NetworkServer.Spawn game object

Updated on May 5, 2018 in  [R] Scripts
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on May 5, 2018

 Hi,

I am making a turn based game where each player shoots a projectile. I have a camera script for following the projectile.

 

I have this script for shooting the projectile:

 

[Command]
void CmdShoot(float power,float angle)
{
GameObject projectile = Shoot(power, angle);
NetworkServer.Spawn(projectile);
}

 

This runs on the server and correctly spawns the projectile on all clients. Question is, how do I run the follow script on the client?

 

[ClientRpc]
public void RpcFocusOn(NetworkInstanceId id)
{
GameObject localObject = ClientScene.FindLocalObject(id);
target = localObject.transform;
this.enabled = true;
}

I tried various ways to get the network identifier of the spawned projectile to pass to the rpc, but it always gives an NPE exception.

Am I going about this the wrong way?

 

thanks

 

  • Liked by
Reply