How to set initial player positions at unique spawn points?

Options
Below is my code and I don't know where I am lacking.
Here some players are generated on same positions .I don't know how to fix.
Please tell me how to sync list of used positons to each other players?
Thanks in adnavce


using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class phtonplayer : Photon.MonoBehaviour {

// Use this for initialization
public GameObject gm;
[SerializeField]
public List usedSpot = new List();

void Start ()
{

gm = GameObject.Find ("NetworkManager");
if (photonView.isMine)
{
this.transform.position = gm.transform.GetComponent ().spwanPos [0].position;
gm.transform.GetComponent ().spwanNames [0].text = photonView.viewID.ToString();
Debug.Log ("My Photon Player :"+this.name);
}
else
{
int currentindex=Random.Range(1,gm.transform.GetComponent ().spwanPos.Length);

while(usedSpot.Contains(currentindex))
{
currentindex = Random.Range (0, gm.transform.GetComponent ().spwanPos.Length);

}
this.transform.position = gm.transform.GetComponent ().spwanPos[currentindex].position;
gm.transform.GetComponent ().spwanNames [currentindex].text = photonView.viewID.ToString();
photonView.RPC("addPos",PhotonTargets.AllBufferedViaServer,currentindex);
}
}


// Update is called once per frame


[PunRPC]
public void addPos(int Id)
{
usedSpot.Add (Id);
}
}

Answers

  • Dodia3D
    Options
    I just figure out this as a silly problem :open_mouth:
    I was using list for every player ,instead one list for all player of used position (i.e. one list in Network manager)and it worked.
    Thanks .