Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Start () {
- Random.seed = 1;
- for (int i = 0; i < planets.Length; i++)
- {
- float chunkX = Mathf.Round(player.transform.position.x / areaHeight);
- float chunkY = Mathf.Round(player.transform.position.y / areaWidth);
- Vector2 pointLoc = new Vector2(gameObject.transform.position.x + Random.Range(areaWidth / 2, -areaWidth / 2), gameObject.transform.position.y + Random.Range(areaHeight / 2, -areaHeight / 2));
- spawnPoints[i] = Instantiate(nullObject, pointLoc, Quaternion.identity);
- planetLocs.Add(pointLoc);
- }
- for (int i = 0; i < planets.Length; i++)
- {
- if(tempLoc == Vector2.zero)
- {
- if (Vector2.Distance(planetLocs[i], tempLoc) > 10)
- {
- tempLoc = planetLocs[i];
- GameObject planet = Instantiate(planets[i], spawnPoints[i].transform.position, Quaternion.identity);
- planet.tag = "Planet";
- planet.name = "planet" + (Manager.curPlanetID).ToString();
- string plname = "planet" + (Manager.curPlanetID).ToString();
- planetLocs.Add(spawnPoints[i].transform.position);
- XDocument doc = XDocument.Load("planets.xml");
- var myNodes = from rt in doc.Descendants("Planets")
- where rt.Attribute("name") != null && (string)rt.Attribute("name").Value == plname
- select rt;
- foreach (var item in myNodes)
- {
- metal = item.Attribute("metal").Value;
- fuel = item.Attribute("fuel").Value;
- food = item.Attribute("food").Value;
- }
- PlanetResources pl = planet.GetComponent<PlanetResources>();
- if (metal != null)
- {
- Debug.Log(metal);
- int.TryParse(metal, out pl.metal);
- int.TryParse(fuel, out pl.fuel);
- int.TryParse(food, out pl.food);
- }
- else
- {
- pl.metal = Random.Range(3, 10);
- pl.fuel = Random.Range(3, 10);
- pl.food = Random.Range(3, 10);
- }
- Debug.Log(metal + " " + fuel + " " + food);
- Manager.curPlanetID++;
- }
- } else
- {
- tempLoc = planetLocs[i];
- GameObject planet = Instantiate(planets[i], spawnPoints[i].transform.position, Quaternion.identity);
- planetLocs.Add(spawnPoints[i].transform.position);
- planet.tag = "Planet";
- planet.name = "planet" + (Manager.curPlanetID).ToString();
- string plname = "planet" + (Manager.curPlanetID).ToString();
- XDocument doc = XDocument.Load("planets.xml");
- var myNodes = from rt in doc.Descendants("Planets")
- where rt.Attribute("name") != null && (string)rt.Attribute("name").Value == plname
- select rt;
- foreach (var item in myNodes)
- {
- if(item.Attribute("metal") != null)
- {
- metal = item.Attribute("metal").Value;
- fuel = item.Attribute("fuel").Value;
- food = item.Attribute("food").Value;
- PlanetResources ar = planet.GetComponent<PlanetResources>();
- if (metal != null)
- {
- int.TryParse(metal, out ar.metal);
- int.TryParse(fuel, out ar.fuel);
- int.TryParse(food, out ar.food);
- }
- else
- {
- ar.metal = (int)Random.Range(3f, 10f);
- ar.fuel = (int)Random.Range(3f, 10f);
- ar.food = (int)Random.Range(3f, 10f);
- }
- }
- }
- Manager.curPlanetID++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement