Hello, I have a script that spawns enemies in a wave based fashion but I am having trouble figuring out how to instance my enemy gameobjects over the pun network. I already have the Photon view and everything on the gameobject but i’m not sure how to actually instance it over the network so other player can see the enemies. My current code for spawning enemies is this:
GameObject instance = (GameObject)Instantiate (zombieEnemy2, near [spawnPointIndex].position, near [spawnPointIndex].rotation);
instance.transform.Rotate (Vector3.up, Random.Range (0f, 360f));
well there are multiple questions that come up here:
what do you do with the zombies? Are they also synced by position? if yes they have a PhotonView and you must use PhotonNetwork.Instantiate.
If you use some other sync method (which i’d highly recommend) the your spawner script needs some kind of RPC.
So your spawn function SpawnZombie
gust gets an extra argument, say int spawnIndex
and the one player (most probably the master client) should call the function:
photonView.RPC("SpawnZombie", RpcTarget.All, hereGoesTheNumberOfYourSpawn);
This will the call the named function on ALL players currently connected to your room.
Assuming that your function is:
[PunRPC]
public void SpawnZombie(int spawnIndex)
{
GameObject instance = (GameObject)Instantiate (zombieEnemy2, near [spawnIndex].position, near [spawnIndex].rotation);
}
As you might notice i removed the rotate part from the code since that would not be synced with the current version.
So for the random rotation you have to add another argument to the RPC so that the random rotation is decided once for all players by the player why calls the RPC.
Let me know if that helped/if something was unclear.
Okay after tweaking some things your answer works. Thank you 