/// <summary> /// Modifies the map according to the number players connected. /// </summary> public bool playerConnected() { players = GameObject.FindGameObjectsWithTag("Player"); powCount = 0; while (Mathf.Pow(2, powCount) <= players.Length) powCount++; // THOUGHT: Maybe have a look at Mathf.Log() powCount--;//need to go one step back, as the loop above will stop when one step further in the calculation of the pow count //if any of the map rings have sunked previously and we need to spawn new ones. //if (powCount > map.transform.childCount - 1 && powCount > ringsSpawned - ringsSunk) if (powCount > map.transform.childCount - 1) { startSinking(); // if the number of players requires more map rings than already present, generate them. if (!sinkingARing) { //thickness represents how many extra ring components will the new map ring contain, based on the number of players thickness = 8f / Mathf.Pow(2, powCount - 1); //increase the number of rings Spawned, substracting the ones that have sunk, to keep track of how many rings are on the map atm. ringsSpawned = ringsSpawned - ringsSunk + 1; GameObject ringNo = new GameObject(); //create a new Ring parent for the the map parts to be spawned ringNo.transform.parent = map.transform; //add the new Ring as a child to the map GameObject ringNo.transform.name = ringsSpawned.ToString(); //give it the name of it's ring number ringNo.transform.tag = "Ring"; mapPartBehavior mapPart = ringNo.AddComponent<mapPartBehavior>() as mapPartBehavior; mapData = ringNo.AddComponent<MeshGenerator>() as MeshGenerator; mapData.AlocateMeshData((int)(thickness + radius) * 2, (int)(thickness + radius) * 2); ringDrawing((int)thickness, ringNo); // need to deal with a float thickness to account for smaller rings. //Set the Layer to Ground. ringNo.transform.gameObject.layer = LayerMask.NameToLayer("Ground"); print("RngNo Layer = " + ringNo.transform.gameObject.layer); //Remove redundant vertices. HashSet<Vector3> noDuplicateVertices = new HashSet<Vector3>(); Vector3[] vertices = ringNo.GetComponent<MeshFilter>().mesh.vertices; for (int i = 0; i < vertices.Length; i++) { noDuplicateVertices.Add(vertices[i]); } Vector3[] newVertices = new Vector3[noDuplicateVertices.Count]; noDuplicateVertices.CopyTo(newVertices); //Add the new ring to the List of the map. //map.GetComponent<EnvironmentPlacement>().AddSection(ringNo, newVertices); } else { sinkingARing = false; int mapRingsNo = map.transform.childCount; Transform temp = map.transform.GetChild(mapRingsNo - 1); mapPartBehavior partsToSink = temp.GetComponent<mapPartBehavior>(); if (partsToSink != null) partsToSink.stopSinking(); } return true; } return false; }