PhotonNetwork.Instantiate
photon instantiate1 is similar to unity initialisation except
- It takes a string (e.g., “MyPrefabName”). Place the prefab in
Assets > Resources
and pass the prefab’s name as the string. - The prefab must have a photon view attached to it.
syntax2: PhotonNetwork.Instantiate(string, location, rotation, custom properties);
PhotonNetwork.Instantiate("MyPrefabName", new Vector3(0, 0, 0), Quaternion.identity, 0);
PunRPC
Some specifications of using RPC:
- The function name is passed as a string (e.g., “RPC function”) and the function parameters are passed as variables.
- RPC function variables have to be PUN serialisable 3.
- The GameObject that the script is attached to must also have a photon view.
syntax4: photonView.RPC("RPC function", RpcTarget.All, [variable1], [variable2]...)
//RPC Fn Call
_photonView.RPC("CreateLineOnAllClients", RpcTarget.All, PhotonNetwork.LocalPlayer.ActorNumber, _currentLineID, localStartPosition);
//Function
private void CreateLineOnAllClients(int actorNumber, int lineID, Vector3 localStartPosition)
{
GameObject newLine = Instantiate(linePrefab, Vector3.zero, Quaternion.identity)
}
The function call can be defined using rpcTarget to specify who will receive the information. RpcTarget.All
, RpcTarget.OthersBuffered
are used frequently.