Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.51 KB | None | 0 0
  1. void Start () {
  2.  
  3.         Random.seed = 1;
  4.         for (int i = 0; i < planets.Length; i++)
  5.         {
  6.            
  7.  
  8.                 float chunkX = Mathf.Round(player.transform.position.x / areaHeight);
  9.                 float chunkY = Mathf.Round(player.transform.position.y / areaWidth);
  10.             Vector2 pointLoc = new Vector2(gameObject.transform.position.x + Random.Range(areaWidth / 2, -areaWidth / 2), gameObject.transform.position.y + Random.Range(areaHeight / 2, -areaHeight / 2));
  11.                 spawnPoints[i] = Instantiate(nullObject, pointLoc, Quaternion.identity);
  12.             planetLocs.Add(pointLoc);
  13.            
  14.         }
  15.         for (int i = 0; i < planets.Length; i++)
  16.         {
  17.             if(tempLoc == Vector2.zero)
  18.             {
  19.                 if (Vector2.Distance(planetLocs[i], tempLoc) > 10)
  20.                 {
  21.  
  22.                     tempLoc = planetLocs[i];
  23.                     GameObject planet = Instantiate(planets[i], spawnPoints[i].transform.position, Quaternion.identity);
  24.                     planet.tag = "Planet";
  25.                     planet.name = "planet" + (Manager.curPlanetID).ToString();
  26.                     string plname = "planet" + (Manager.curPlanetID).ToString();
  27.                     planetLocs.Add(spawnPoints[i].transform.position);
  28.                     XDocument doc = XDocument.Load("planets.xml");
  29.                     var myNodes = from rt in doc.Descendants("Planets")
  30.                                   where rt.Attribute("name") != null && (string)rt.Attribute("name").Value == plname
  31.                                   select rt;
  32.                     foreach (var item in myNodes)
  33.                     {
  34.                         metal = item.Attribute("metal").Value;
  35.                         fuel = item.Attribute("fuel").Value;
  36.                         food = item.Attribute("food").Value;
  37.  
  38.                     }
  39.                     PlanetResources pl = planet.GetComponent<PlanetResources>();
  40.                     if (metal != null)
  41.                     {
  42.                         Debug.Log(metal);
  43.                         int.TryParse(metal, out pl.metal);
  44.                         int.TryParse(fuel, out pl.fuel);
  45.  
  46.                         int.TryParse(food, out pl.food);    
  47.                     }
  48.                     else
  49.                     {
  50.                         pl.metal = Random.Range(3, 10);
  51.                         pl.fuel = Random.Range(3, 10);
  52.                         pl.food = Random.Range(3, 10);
  53.                     }
  54.  
  55.                     Debug.Log(metal + " " + fuel + " " + food);
  56.                     Manager.curPlanetID++;
  57.  
  58.  
  59.  
  60.  
  61.                 }
  62.             } else
  63.             {
  64.                 tempLoc = planetLocs[i];
  65.  
  66.                 GameObject planet = Instantiate(planets[i], spawnPoints[i].transform.position, Quaternion.identity);
  67.                
  68.                 planetLocs.Add(spawnPoints[i].transform.position);
  69.                 planet.tag = "Planet";
  70.                 planet.name = "planet" + (Manager.curPlanetID).ToString();
  71.                 string plname = "planet" + (Manager.curPlanetID).ToString();
  72.  
  73.                 XDocument doc = XDocument.Load("planets.xml");
  74.                 var myNodes = from rt in doc.Descendants("Planets")
  75.                               where rt.Attribute("name") != null && (string)rt.Attribute("name").Value == plname
  76.                               select rt;
  77.                
  78.                 foreach (var item in myNodes)
  79.                 {
  80.                     if(item.Attribute("metal") != null)
  81.                     {
  82.  
  83.                         metal = item.Attribute("metal").Value;
  84.                         fuel = item.Attribute("fuel").Value;
  85.                         food = item.Attribute("food").Value;
  86.                         PlanetResources ar = planet.GetComponent<PlanetResources>();
  87.                         if (metal != null)
  88.                         {
  89.  
  90.                             int.TryParse(metal, out ar.metal);
  91.                             int.TryParse(fuel, out ar.fuel);
  92.  
  93.                             int.TryParse(food, out ar.food);
  94.                         }
  95.                         else
  96.                         {
  97.                             ar.metal = (int)Random.Range(3f, 10f);
  98.                             ar.fuel = (int)Random.Range(3f, 10f);
  99.                             ar.food = (int)Random.Range(3f, 10f);
  100.                         }
  101.                     }
  102.  
  103.                
  104.                 }
  105.                
  106.                 Manager.curPlanetID++;
  107.             }
  108.            
  109.         }
  110.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement