Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by resulozkaya · Apr 14, 2018 at 09:50 PM · networkingphotonspawning

Photon Networking: How to spawn my players at the another places?

I'm working on multiplayer game and i'm using Photon Networking. I'm trying to spawn my players at the different places but i'cant do that. I tried to do that with their id's but i couldn't.

Here is my code:

 using System.IO;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class PlayerNetwork : Photon.MonoBehaviour {
 
 
     public static PlayerNetwork Instance;
     public string PlayerName { get; private set; }
     private PhotonView PhotonView;
     private int PlayersInGame = 0;
     public GameObject playerPrfb;
 
     private void Awake ()
     {
         Instance = this;
         PhotonView = GetComponent<PhotonView>();
         PlayerName = "Resul" + Random.Range(1000, 9999);
 
         PhotonNetwork.sendRate = 60;
         PhotonNetwork.sendRateOnSerialize = 30;
 
         SceneManager.sceneLoaded += OnSceneFinishedLoading;
     }
 
 
     private void OnSceneFinishedLoading(Scene scene, LoadSceneMode mode)
     {
         if(scene.name == "Multiplayer1")
         {
             if (PhotonNetwork.isMasterClient)
                 MasterLoadedGame();
             else
                 NonMasterLoadedGame();
         }
     }
 
     private void MasterLoadedGame()
     {
         PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient);
         PhotonView.RPC("RPC_LoadGameOthers", PhotonTargets.Others);
     }
 
     private void NonMasterLoadedGame()
     {
         PhotonView.RPC("RPC_LoadedGameScene", PhotonTargets.MasterClient);
     }
 
     [PunRPC]
     private void RPC_LoadGameOthers()
     {
         PhotonNetwork.LoadLevel(18);
     }
 
     [PunRPC]
     private void RPC_LoadedGameScene()
     {
         PlayersInGame++;
         if(PlayersInGame == PhotonNetwork.playerList.Length)
         {
             print("All players are in the game scene ");
             PhotonView.RPC("RPC_CreatePlayer", PhotonTargets.All);
         }
     }
     
     [PunRPC]
     private void RPC_CreatePlayer()
     {
  
             PhotonNetwork.Instantiate(Path.Combine("Prefabs", "Plyr"), new Vector2(1.34f, 4.711f), Quaternion.identity, 0);
 
     }   
 
 }
 

as you can see on the RPC_CreatePlayer my all players spawning at the same place. Thanks for any help.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by ChristianSimon · Apr 17, 2018 at 10:16 AM

Hi,

while editing the scene you can already place some spawn points and make them available in code. Then each client can select a spawn position to spawn his character on a certain spot.

To do this, you can use the PlayerRoomIndexing for example which applies a unique 'index' to each client in the room. You can access this value on the local client by using PlayerRoomIndexing.instance.GetRoomIndex(PhotonNetwork.player) for example. You can map this unique index to a certain spawn point where the client can spawn his character.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-1

Answer by asadmubashr · Feb 10, 2021 at 12:58 AM

Please brother if you found answer and have implemented this structure, can you share code... please you can save my days.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

124 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Instance GameObjects Over the Pun Network 2 Answers

Photon Network, how to spawn FPSController from Unity Standard Assets? 2 Answers

[UNET] Dynamically position NetworkStartPosition Gameobjects 2 Answers

How to modify enemy players meshs with Photon Unity Networking? 1 Answer

Photon Cloud Networking: OnPhotonSerializeView Not Firing 9 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges