Спавн игроков в юнити в разных скинах
Уже неделю бьюсь на тем как сделать, чтобы игроки спавнились в разных скинах в онлайн игре(то есть из list удалялся скин который не надо спавнить). Вот что уже попробовал написать( не работает):
public List<GameObject> players;
GameObject s;
public int l = -1;
GameObject rand;
GameObject hug;
GameObject gh1;
GameObject gh2;
GameObject gh3;
GameObject gh4;
GameObject gh5;
GameObject gh6;
GameObject gh7;
GameObject gh8;
GameObject gh9;
GameObject gh10;
void Awake()
{
gh1 = Resources.Load("amongus") as GameObject;
gh2 = Resources.Load("amongus 1") as GameObject;
gh3 = Resources.Load("amongus 2") as GameObject;
gh4 = Resources.Load("amongus 3") as GameObject;
gh5 = Resources.Load("amongus 4") as GameObject;
gh6 = Resources.Load("amongus 5") as GameObject;
gh7 = Resources.Load("amongus 6") as GameObject;
gh8 = Resources.Load("amongus 7") as GameObject;
gh9 = Resources.Load("amongus 8") as GameObject;
gh10 = Resources.Load("amongus 9") as GameObject;
}
// Start is called before the first frame update
void Start()
{
if (PlayerPrefs.GetInt("am") == 1)
{
players.Remove(gh1);
}
if (PlayerPrefs.GetInt("am1") == 2)
{
players.Remove(gh2);
}
if (PlayerPrefs.GetInt("am2") == 3)
{
players.Remove(gh3);
}
if (PlayerPrefs.GetInt("am3") == 4)
{
players.Remove(gh4);
}
if (PlayerPrefs.GetInt("am4") == 5)
{
players.Remove(gh5);
}
if (PlayerPrefs.GetInt("am5") == 6)
{
players.Remove(gh6);
}
if (PlayerPrefs.GetInt("am6") == 7)
{
players.Remove(gh7);
}
if (PlayerPrefs.GetInt("am7") == 8)
{
players.Remove(gh8);
}
if (PlayerPrefs.GetInt("am8") == 9)
{
players.Remove(gh9);
}
if (PlayerPrefs.GetInt("am9") == 10)
{
players.Remove(gh10);
}
rand = players[Random.Range(0, players.Count)];
foreach (GameObject k in players)
{
l += 1;
hug = players[l];
if (hug == rand)
{
PhotonNetwork.Instantiate(rand.name, new Vector3(Random.Range(0, players.Count), -1.142f, 0), Quaternion.identity);
players.RemoveAt(l);
if(hug.gameObject.name == "amongus")
PlayerPrefs.SetInt("am", 1);
else if(hug.gameObject.name == "amongus 1")
PlayerPrefs.SetInt("am1", 2);
else if (hug.name == "amongus 2")
PlayerPrefs.SetInt("am2", 3);
else if (hug.name == "amongus 3")
PlayerPrefs.SetInt("am3", 4);
else if (hug.name == "amongus 4")
PlayerPrefs.SetInt("am4", 5);
else if (hug.name == "amongus 5")
PlayerPrefs.SetInt("am5", 6);
else if (hug.name == "amongus 6")
PlayerPrefs.SetInt("am6", 7);
else if (hug.name == "amongus 7")
PlayerPrefs.SetInt("am7", 8);
else if (hug.name == "amongus 8")
PlayerPrefs.SetInt("am8", 9);
else if (hug.name == "amongus 9")
PlayerPrefs.SetInt("am9", 10);
l = -1;
return;
}
}
}
// Update is called once per frame
void Update()
{
}
public void Leave()
{
PhotonNetwork.LeaveRoom();
}
public override void OnLeftRoom()
{
SceneManager.LoadScene(0);
}
Это скрипт GameManager, который спавнит игроков(с моим тупым кодом). Онлайн делаю через photon.