This script worked perfect…then I ran a build to test…then tried to add and remove certain objects now players disapear on start…
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class PlayerSelection : MonoBehaviour {
private GameObject[] Players;
int index;
void Start()
{
index = PlayerPrefs.GetInt ("playerselect");
Players = new GameObject[transform.childCount];
//
for (int i = 0; i < transform.childCount; i++)
Players [i] = transform.GetChild (i).gameObject;
//
foreach (GameObject go in Players)
go.SetActive (false);
if (Players [index])
Players [index].SetActive (true);
}
public void ToggleLeft ()
{
Players[index].SetActive (false);
index--;
if (index < 0)
index = Players.Length - 1;
Players [index].SetActive (true);
}
public void ToggleRight ()
{
Players [index].SetActive (false);
index++;
if (index < 0)
index = Players.Length - 1;
Players [index].SetActive (true);
}
public void Select()
{
PlayerPrefs.SetInt ("playerselect", index);
SceneManager.LoadScene("Shooter");
}
}