- Home /
Photon Network Instantiate Objects over Network
Hello, need a bit of help:
I am trying to spawn an object in front of the player over the network and allow all players to see that object, but:
Instantiate(BuildingObjects [CurrentObj].gameObject, obj.position, obj.rotation);
shows the object on my view, but not others.
I have tried to add PhotonNetwork.Instantiate... to it, but throws the error:
No overload method for method instantiate, takes 3 methods.
---- Am I missing something here?? -- I have an RPC set up above the void, but not sure how to call this so that everyone can see the object being spawned over the network.
I have been looking at this code for far too long and need a little bit of help!
You should take a look at the error message, not at your code.
In worst case, try to search the error message "as is" in the internet to find help.
Do the $$anonymous$$arco Polo Tutorial. Code it. Don't just read it.
Answer by Jeff00001 · Nov 30, 2014 at 03:30 PM
Something like:
[RPC]
void Spawning () {
if (PhotonNetwork.isMasterClient) {
SpawnedObject obj = PhotonNetwork.Instantiate ("Enemies", transform.position, transform.rotation,0);
}
Put your prefab in the root of the resources folder and make sure the prefab's name reflects the string, i.e. Enemies
Important in that solution is the "is$$anonymous$$asterClient". With the RPC you ask the $$anonymous$$aster Client to Instantiate an enemy. The RPC itself is very likely sent to everyone but only the $$anonymous$$aster Client should react. Else you spawn multiple enemies.
As tip: Use InstantiateSceneObject() on the $$anonymous$$aster Client. This makes sure the enemy stays in the room, even if the current $$anonymous$$aster Client leaves.
please Tobias, may I have more about your tip InstantiateSceneObject()?
Hi alarm656. This would work as an example:
if (***PhotonNetwork.is$$anonymous$$asterClient***) {
int RandNum = Random.Range (0, botSpawnSpots.Length);
BotSpawnSpot botSpawnSpot = botSpawnSpots [RandNum];
GameObject enemy = (GameObject)PhotonNetwork.InstantiateSceneObject ("Enemy2", botSpawnSpot.transform.position, Quaternion.identity, 0, null);
enemy.GetComponent<PhotonView> ().RPC ("SetTeamID", PhotonTargets.AllBuffered, 9);
}
Tobiass, correct me if I'm going in the wrong direction, but from his needs, The $$anonymous$$aster client Should Control: - $$anonymous$$ovement - Health Points - Destroying Scene object. - Any other functions that rely Enemy Interaction.
Hi, purpl3grape. Thank you for your answer to me. From your scrip I understood that I need additional "BotSpawnSpot" script right? Actually I would like to know projectile shooting with visible bullets by using RPC method. So please if you have a time could you open this link and correct me please. I can't sync bullet across network. http://forum.photonengine.com/discussion/7624/shooting-like-in-demo-project-angry-bots#latest
This links directs you to my question in photon engine forum. Any help will be appreciated. Thanks in advance. Hope you'll make my day today:)
Your answer
Follow this Question
Related Questions
Proper way to instantiate projectile in PUN 1 Answer
Sync An Object not Controlled by Players 1 Answer
RPC failed to send 1 Answer