/** * myInitialize- initializes all environment squares and gives them some units of oxygen. */ public void myInitialize() { Debug.Log("Initializing environment"); int widthToTrack = 0; int heightToTrack = 0; for (int i = 0; i < width * height; i++) { int x = widthToTrack * squareLength; int y = heightToTrack * squareLength; GameObject oneSquare = (GameObject)PhotonNetwork.Instantiate("EnvironmentSquare", new Vector3(x, y), Quaternion.identity, 0); EnvironmentControllerScript conSquare = oneSquare.GetComponent <EnvironmentControllerScript>(); conSquare.changeZoneNum(i); //Add oxygen to the square conSquare.addGas(new OxygenScript(1, 1)); if (conSquare == null) { Debug.Log("Environment controller script was null for a square"); } widthToTrack++; if (widthToTrack >= width) { widthToTrack = 0; heightToTrack++; } } Debug.Log("Environment initialized."); }
/* * Records that the player has left the environment e. */ public void removeEnvironment(EnvironmentControllerScript e) { int zoneToRemove = e.getZoneNum(); foreach (EnvironmentControllerScript env in envs) { if (env.getZoneNum() == zoneToRemove) { envs.Remove(env); return; } } Debug.Log("Could not remove the given environment."); }
void attemptToSpawnLand() { land = LandControllerScript.FindObjectOfType <LandControllerScript> (); if (land == null) { return; } Debug.Log("Initializing land."); EnvironmentControllerScript[] envs = EnvironmentControllerScript.FindObjectsOfType <EnvironmentControllerScript>(); if (envs.GetLength(0) == 0) { Debug.Log("Found no environment controller scripts."); } foreach (EnvironmentControllerScript env in envs) { env.changeParentTo(land.transform); } Debug.Log("Land initialized."); }
/** * SpawnInitialLand- If this player created the room, spawn the initial environment square units */ void SpawnInitialLand() { if (instantiateEverything) { Debug.Log("Initial land spawn."); GameObject landObject = (GameObject)PhotonNetwork.Instantiate("Land", Vector3.zero, Quaternion.identity, 0); land = landObject.GetComponent <LandControllerScript>(); land.myInitialize(); //Set squares as children of Land EnvironmentControllerScript[] envs = EnvironmentControllerScript.FindObjectsOfType <EnvironmentControllerScript>(); if (envs.GetLength(0) == 0) { Debug.Log("Found no environment controller scripts."); } foreach (EnvironmentControllerScript env in envs) { env.changeParentTo(land.transform); } } }
/* * Records that the player is in given environment e */ public void giveEnvironment(EnvironmentControllerScript e) { envs.AddLast(e); }