/**Initialises the game settings based on * info from the initialisation info object that is passed to the level * when it is loaded */ private void InitialiseGame() { if (!initialised) { initialised = true; Debug.Log("initialising"); //Get the initialisation info from the singleton class InitialisationInfo info = InitialisationInfo.getInitialisationInfo(); //Set level attributes isMultiplayer = info.isMultiplayer; level = info.level; //Set player1 attributes player1Score = info.player1Score; player1ID = info.player1ID; player1Name = info.player1Name; //Instantiate player object at start spawn GameObject p1StartPosition = GameObject.FindWithTag("P1 Start"); GameObject player = (GameObject)Instantiate(Resources.Load(info.player1Character), p1StartPosition.transform.position, Quaternion.identity); //Set the player number on the player object PlayerController playerController = player.GetComponent <PlayerController>(); playerController.setPlayerNumber(1); //If multiplayer set player2 attributes if (isMultiplayer) { player2Score = info.player2Score; GameObject p2StartPosition = GameObject.FindWithTag("P2 Start"); player = (GameObject)Instantiate(Resources.Load(info.player2Character), p2StartPosition.transform.position, Quaternion.identity); playerController = player.GetComponent <PlayerController>(); player2ID = info.player2ID; player2Name = info.player2Name; //Below only for testing multiplayer in one game instance with different keyboard inputs assigned if (info.isTest) { Destroy(playerController); player.AddComponent <OtherPlayerController>(); playerController = player.GetComponent <PlayerController>(); } //Set the player number on the instantiated object playerController.setPlayerNumber(2); } else { //Otherwise hide the player 2 score and health info on the canvas GameObject p2Info = GameObject.FindGameObjectWithTag("P2Info"); p2Info.SetActive(false); } } }
/**Input the test data on awake (before start) * */ void Awake() { info = new InitialisationInfo(); info.isMultiplayer = false; info.level = 11; info.isTest = true; info.player1Character = "Satyr"; info.player1Score = 1000; info.player2Character = "Pink"; info.player2Score = 2000; }
//Returns the instance of the singleton class //Creates a new object with default values if instance does not yet exist public static InitialisationInfo getInitialisationInfo() { if (info == null) { //Initialise all variables with default data for testing info = new InitialisationInfo(); info.isMultiplayer = false; info.isSavedGame = false; info.level = 1; info.difficulty = "Easy"; info.player1ID = "DefaultID"; info.player1Name = "DefaultName"; info.player1Character = "NinjaGirl"; info.player1Lives = 3; info.player1Score = 0; } return(info); }
void Awake() { info = new InitialisationInfo(); }
public void updateInitialisationInfo(InitialisationInfo info) { this.info = info; }
//Updates the singleton instance with newInfo public static void setInitialisationInfo(InitialisationInfo newInfo) { info = newInfo; }