void SpawnPlayers() { PersistentGameState pgs = FindObjectOfType <PersistentGameState>(); players = new Player[2]; if (!pgs) // This will ONLY happen when testing in unity { pgs = PersistentGameState.CreateDefault(); } for (int i = 0; i < 2; i++) { GameObject o = (GameObject)Instantiate(playerPrefab, spawnPoints[i].position, Quaternion.identity); Player p = o.GetComponent <Player>(); p.playerNum = i; p.inputMethod = pgs.inputMethods[i]; FreeLook fl = p.lookCamera.GetComponent <FreeLook>(); fl.inputMethod = pgs.inputMethods[i]; fl.sensitivity.y *= pgs.invertAxes[i] == 0 ? 1 : -1; var r = p.lookCamera.rect; r.x = i * 0.5f; p.lookCamera.rect = r; p.fridgeCamera.rect = r; // p.skin = pgs.skin[i]; players[i] = p; } Destroy(pgs); }
void Awake() { if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); } else { DestroyImmediate(gameObject); } }
// skin data public static PersistentGameState CreateDefault() { GameObject o = new GameObject("DefaultGameSettings", typeof(PersistentGameState)); PersistentGameState pgs = o.GetComponent <PersistentGameState>(); pgs.inputMethods[0] = PlayerInputMethod.KeyboardMouse; pgs.inputMethods[1] = PlayerInputMethod.Controller; pgs.invertAxes[0] = ControlMode.Standard; pgs.invertAxes[1] = ControlMode.Standard; return(pgs); }
// Use this for initialization void Start() { Screen.lockCursor = false; GameObject o = new GameObject("GameSettings", typeof(PersistentGameState)); DontDestroyOnLoad(o); pgs = o.GetComponent <PersistentGameState>(); foreach (Button b in screenButtons) { b.Selected = false; } }