PLAYER POSITION IN NETWORK.

Options
Hello,

i am working on 2d multiplayer game. in which gameplay is like .. there is one table in which maximum 6 player can join this table or room. the main concepts is that in home player of all connected device should be at center of the table. and all other are at another position. After generate player in hierarchy i check for Photnview.ismine and set position of player and also check if player is not local player than position of player in network. and there are 5 position in Array. when any player pick any one position than i delete this position using RPC method. so next player in network cant generate at same position. but my player cant generate . Please help me.

Following is my code to understand this situation.
Normal instantiate for player generation.

From NetworkManager_new Script -

public Transform[] Spanpoints = new Transform[5];
public Transform[] Centerpos = new Transform[1];

player = PhotonNetwork.Instantiate ("Player_1",Vector3.zero, Quaternion.identity, 0);

in another script which i attached instantiated Player.

Networkmover script which i attached to generated player.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;

public class Networkmover : Photon.MonoBehaviour
{

public Vector3[] Spanpoints_1 = new Vector3[5];
public Vector3[] centerpos_1 = new Vector3[1];
public int index;
public bool isComplete = false;

NetworkManager_new NetMan;

// Use this for initialization
void Start ()
{


Vector3 pos1 = GameObject.Find ("NetworkManager").GetComponent ().Spanpoints [0].transform.position;
Vector3 pos2 = GameObject.Find ("NetworkManager").GetComponent ().Spanpoints [1].transform.position;
Vector3 pos3 = GameObject.Find ("NetworkManager").GetComponent ().Spanpoints [2].transform.position;
Vector3 pos4 = GameObject.Find ("NetworkManager").GetComponent ().Spanpoints [3].transform.position;
Vector3 pos5 = GameObject.Find ("NetworkManager").GetComponent ().Spanpoints [4].transform.position;

Vector3 centerpoints = GameObject.Find ("NetworkManager").GetComponent ().Centerpos [0].transform.position;

Spanpoints_1 [0] = pos1;
Spanpoints_1 [1] = pos2;
Spanpoints_1 [2] = pos3;
Spanpoints_1 [3] = pos4;
Spanpoints_1 [4] = pos5;

centerpos_1 [0] = centerpoints;

Debug.Log ("spa"+Spanpoints_1[0]);

if (photonView.isMine)
{
this.transform.position = centerpos_1[0];
Debug.Log("Mine" + this.transform.name);
}

else
{
index = Random.Range (0, Spanpoints_1.Length);
this.transform.position = Spanpoints_1[index];
change(index);

}
}

void change (int index1)
{
photonView.RPC("IndexChange_Rpc", PhotonTargets.AllBuffered, index);
}


[PunRPC]
public void IndexChange_Rpc(int index1)
{
List t = new List();
for(int i = 0 ;i < Spanpoints_1.Length; i++)
{
if(i!= index)
t.Add(Spanpoints_1[i]);
}

Spanpoints_1 = new Vector3[Spanpoints_1.Length -1 ];
for(int j=0 ; j<t.Count; j++)
{
Spanpoints_1[j] = t[j];
}
t.Clear ();
Debug.Log (index);
}

i didnt get nay error but in one device my player generated at different location but in one device both player are at center position. what am i dong wrong???

Comments

  • hello i have solve this issue many times before just forget to update. i have used different approaches to generate player in home at center position and remotely at random position.

    First if our player is not home player than provide amy random position form array and store this position to list and Broadcast this list list to all player than any new player arrive in my room than he will only get those position which are empty.

    so with this i have solve this issue.