Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
  • Help Room /
avatar image
0
Question by Dok101 · Jul 28, 2015 at 09:12 AM · multiplayerphotonspawnspawnpoints

How to identify players on Photon Unity?

Hey

Im trying to make a multiplayer racing game using Photon Unity, but Im not sure how to assign unique IDs to the players. What I'm trying to do is once the players create/join their room, they don't all spawn at the same spawn point, but rather, one person spawns per spawn point.

For example heres the code for the NetworkManager currently

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour {
 
     private const string Version = "v1.0";
     public string roomname = "MultiplayerRoom";
     public string playerPrefabName = "MultiplayerCar01";
     public Transform spawnpoint_1;
     public Transform spawnpoint_2;
     public Transform spawnpoint_3;
     public Transform spawnpoint_4;
     public Transform spawnpoint_5;
     public Transform spawnpoint_6;
     public Transform spawnpoint_7;
     public Transform spawnpoint_8;
 
 
     void OnJoinedRoom ()
     {
         if (PhotonNetwork.room.playerCount == 8)
         StartGame ();
     }
 
     void StartGame ()
     {
         PhotonNetwork.Instantiate(playerPrefabName,
                                   spawnpoint_1.position,
                                   spawnpoint_1.rotation,
                                   0);
     }
 
     void Start () {
         PhotonNetwork.ConnectUsingSettings(Version);
     }
 
     void OnJoinedLobby () {
         RoomOptions roomOptions = new RoomOptions() { isVisible = true, maxPlayers = 8 };
         PhotonNetwork.JoinOrCreateRoom(roomname, roomOptions, TypedLobby.Default);
     }
 
     }
 

As you can see I have 8 spawn points but my question is how do I differentiate the players so that Player 1 goes to spawn point 1, Player 2 to spawn point 2 etc.

Thanks

Comment
Add comment · Show 1
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 Positive7 · Jul 28, 2015 at 10:40 AM 0
Share

Create an array of the players and use for loop?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by rohankad · Jul 28, 2015 at 12:37 PM

First of all take the spawnpoints as an array of maximum 8. Get the numbers of players connected using the PhotonNetwork.playerList. Run a for loop and set the players to their positions.

Comment
Add comment · Show 5 · 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 Dok101 · Jul 30, 2015 at 07:23 AM 0
Share

Thanks for your answer

I created this script following your advice

 using UnityEngine;
 using System.Collections;
 
 public class Network$$anonymous$$anager : $$anonymous$$onoBehaviour {
 
     private const string Version = "v1.0";
     public string roomname = "$$anonymous$$ultiplayerRoom";
     public string playerPrefabName = "$$anonymous$$ultiplayerCar01";
     public GameObject[] spawnpoints;
     public int Spawnpoint$$anonymous$$ax = PhotonNetwork.room.playerCount;
 
 
     void OnJoinedRoom ()
     {
         if (PhotonNetwork.room.playerCount == 8)
         {
         StartGame ();
         }    
     }
 
     void StartGame ()
     {
         for (int i = 0; i <= Spawnpoint$$anonymous$$ax; i ++)
     {
         PhotonNetwork.Instantiate(playerPrefabName,
                                   spawnpoints[i].position,
                                   spawnpoints[i].rotation,
                                   0);
     }
         
     }
 
     void Start () {
         PhotonNetwork.ConnectUsingSettings(Version);
     }
 
     void OnJoinedLobby () {
         RoomOptions roomOptions = new RoomOptions() { isVisible = true, maxPlayers = 8 };
         PhotonNetwork.JoinOrCreateRoom(roomname, roomOptions, TypedLobby.Default);
     }
 
     }


but I get the errors

Assets/$$anonymous$$ultiplayer/Network/Network$$anonymous$$anager.cs(26,58): error CS1061: Type UnityEngine.GameObject' does not contain a definition for position' and no extension method position' of type UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)

Assets/$$anonymous$$ultiplayer/Network/Network$$anonymous$$anager.cs(27,58): error CS1061: Type UnityEngine.GameObject' does not contain a definition for rotation' and no extension method rotation' of type UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)

Assets/$$anonymous$$ultiplayer/Network/Network$$anonymous$$anager.cs(25,27): error CS1502: The best overloaded method match for PhotonNetwork.Instantiate(string, UnityEngine.Vector3, UnityEngine.Quaternion, int)' has some invalid arguments Assets/$$anonymous$$ultiplayer/Network/Network$$anonymous$$anager.cs(25,27): error CS1503: Argument #2' cannot convert object' expression to type UnityEngine.Vector3'

I don't think that these errors come with the instantiate coding because I used the script before without error.

Do you have any idea how to fix it?

Thanks

avatar image Positive7 · Jul 30, 2015 at 07:26 AM 0
Share
 spawnpoints[i].transform.position,
 spawnpoints[i].transform.rotation,
avatar image Dok101 · Jul 30, 2015 at 07:34 AM 0
Share

Thanks that worked :)

avatar image Chris196 · Dec 13, 2015 at 11:54 PM 0
Share

my player spawns on the same position with this code:

void OnJoinedRoom(){ if (PhotonNetwork.room.playerCount == 1) { GameObject meinSpieler = PhotonNetwork.Instantiate ("Spieler", new Vector3 (-0.95f, 5f, 18f), Quaternion.identity, 0); meinSpieler.transform.localRotation = Quaternion.Euler (0, 180, 0); } if (PhotonNetwork.room.playerCount == 2) { GameObject meinSpieler = PhotonNetwork.Instantiate ("Spieler", new Vector3 (-0.95f, 5f, -18f), Quaternion.identity, 0); } }

if i use your code, just 1 player is spawning. Why is this?

avatar image Chris196 · Dec 14, 2015 at 04:49 AM 0
Share

i have an error with the SpawnPoint$$anonymous$$ax. It says You are not allowed to call this function when declaring a variable

avatar image
0

Answer by michaelheise61 · Jan 14, 2021 at 11:05 AM

spawnpoint[PhotonNetwork.player.ID] as position to instantiate your prefab so spawnpoint should be a vector3 array. Its one line of code. As rotation you could use identity or just make another quaternion array with spawnrotation. That is literally one line of code. excludining defining the arrays.

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

26 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

Related Questions

Unity Photon Next Step? 0 Answers

Unity Photon Next Step? 0 Answers

How to create several spawnpoints without spawning at the same place in Photon 2 Answers

Unity Photon doesn't Spawn Player 0 Answers

Players won't spawn with Photon Unity Network 1 Answer


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