/// <summary> /// Creates a RottenApple prefab at the given position, /// </summary> /// <returns>The spawned RottenApple gameobject</returns> /// <param name="position">The position to spawn the gameobject at.</param> public RottenApple CreateAppleObject(Vector2 position) { RottenApple newApple = Instantiate(applePrefab, position, Quaternion.identity) as RottenApple; newApple.Init(); return(newApple); }
/// <summary> /// This function initializes and forms the location network. /// </summary> public Nest CreateNetwork() { this.nest = PrefabManager.instance.CreateNestObject(Vector2.zero); this.nest.transform.SetParent(transform); this.LocationNetwork = new Network(); Vector2[] firstRing = new Vector2[5]; firstRing[0].x = 6f; firstRing[0].y = 0f; firstRing[1].x = 0f; firstRing[1].y = 4f; firstRing[2].x = -4f; firstRing[2].y = 0f; firstRing[3].x = -3f; firstRing[3].y = -5f; firstRing[4].x = 3f; firstRing[4].y = -5f; // TODO Temp Create network first ring location, around nest EmptyLocation[] tempLocs = new EmptyLocation[firstRing.Length]; for (int i = 0; i < firstRing.Length; i++) { tempLocs[i] = PrefabManager.instance.CreateEmptyLocationObject(firstRing[i]); tempLocs[i].transform.SetParent(transform); // Create network connections CreateNetworkPath(this.nest, tempLocs[i]); } // Connect ring together EmptyLocation prevLoc = tempLocs[tempLocs.Length - 1]; foreach (EmptyLocation loc in tempLocs) { // Create network connections CreateNetworkPath(prevLoc, loc); prevLoc = loc; } Vector2[] secondRing = new Vector2[4]; secondRing[0].x = 8f; secondRing[0].y = 4f; secondRing[1].x = -6f; secondRing[1].y = 6f; secondRing[2].x = -6f; secondRing[2].y = -4f; secondRing[3].x = 0f; secondRing[3].y = -8f; // TODO Temp Create network second ring location, around nest RottenApple[] tempApples = new RottenApple[secondRing.Length]; for (int i = 0; i < secondRing.Length; i++) { tempApples[i] = PrefabManager.instance.CreateAppleObject(secondRing[i]); tempApples[i].transform.SetParent(transform); // Create network connections CreateNetworkPath(tempLocs[i], tempApples[i]); CreateNetworkPath(tempLocs[i + 1], tempApples[i]); } return(this.nest); }