Instantiation

Hello guys,

First of all, I want to state that I am a noob in terms of Unity, C# and Networking.

That being said I try to manage with what I can find on forums, tutorials etc.

I want to Instantiate a prefab on the other player but I can't find documentation anywhere, I'm sure it's going to be too easy as 1,2,3 but I can't seem to manage this one.

Any hints on how to do it?

I used

var newEnemy = PhotonNetwork.Instantiate(enemy1, start.transform.position, Quaternion.identity, 0);

but this instantiates on the local player as well.

Comments

  • Hi @Christos,

    PhotonNetwork.Instantiate instantiates the named object on each client. You can read more about it on the Instantiation documentation page.

    If you only want to instantiate on the local player, you can use Unity's 'standard' Instantiate call. This will instantiate an object only on the client who calls Instantiate.

    If you want a remote client to instantiate a certain object, you have to send a custom event to this client. This can be either done by using RPCs (which requires a set up PhotonView component) or by using the RaiseEvent function, which works independently from a PhotonView component. To see how this works, you can take a look at the RPCs and RaiseEvent documentation page.

    Please note, that objects not instantiated with PhotonNetwork.Instantiate are not synchronized by default.
  • Thank you @Christian_Simon !!! It worked with [PUNRPC]. I am now getting the hang of it RPCs they work like a charm where i wan't them to!

    Again thanks alot!
  • Raise events are a bit out of my league for the moment and do not fully understand them. I will cover them in the near future!
Sign In or Register to comment.