- Home /
Player Instantiate won't work
Hello I'm working on a multiplayer game using photon and I'm trying to instantiate the players but it won't work. Does anyone have any idea why it's not working? Here is the script
public class GameSetup : MonoBehaviour
{
public Transform[] spawnPoints;
void Start()
{
PhotonView PV = PhotonView.Get(this);
PV.RPC("RPC.CreatePlayer", RpcTarget.All);
}
[PunRPC]
private void RPC_CreatePlayer()
{
Player[] players = PhotonNetwork.PlayerList;
for (int i = 0; i < players.Length; i++)
{
PhotonView PV = PhotonView.Get(this);
PV.RPC("playerSpawn", players[3], spawnPoints[i].position, spawnPoints[i].rotation);
}
}
[PunRPC]
void playerSpawn(Vector3 spawnPos, Quaternion spawnRot)
{
PhotonNetwork.Instantiate("Taya", spawnPos, spawnRot, 0);
}
Answer by yuvaansh · Dec 12, 2020 at 05:20 AM
@whatisthislol
If you want to Instantiate the player or "Taya" then Taya should be a prefab and placed in a folder called "Resources" (this folder can be anywhere in the project) then only it would be Instantiated.
I hope this would answer your question :O)
Yes hello I do have the prefab in a folder called "Resources" but it still won't instantiate :(
Answer by CmdrZin · Dec 12, 2020 at 05:32 AM
See
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
you need to have a prefab available, usually by dragging one to a public variable in the Inspector.
Correct me if Im wrong but if PhotonNetwork is being used it should be in string. I already tried putting prefab.name to it but it still won't work :(
Well, the only thing else from the info page
https://doc.photonengine.com/en-us/pun/current/gameplay/instantiation
is "Any prefab must have a PhotonView component".
You seem to have met all of the other requirements.
I also have PhotonView component attached to the prefab thats why Im not sure why it is still not working
Your answer
Follow this Question
Related Questions
Unity photon multiplayer teams 3 Answers
Spawn players in unique places (Photon networking) Object sync problem for entering players. 0 Answers
Photon Instantiate 2 Answers
Is possible to spawn 2d image in photon networking ? 1 Answer
Spawning troubles 2 Answers