Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public int width;
  2. public int height;
  3.  
  4. public string seed;
  5. public bool useRandomSeed;
  6.  
  7. [Range(0, 100)]
  8. public int randomFillPercent;
  9.  
  10. int [,] map;
  11.  
  12. void Start()
  13. {
  14. GenerateMap();
  15. }
  16.  
  17. void GenerateMap()
  18. {
  19. map = new int[width,height];
  20. RandomFillMap();
  21. }
  22.  
  23. void RandomFillMap()
  24. {
  25. if(useRandomSeed)
  26. {
  27. seed = Time.time.ToString();
  28. }
  29.  
  30. System.Random psuedoRandom = new System.Random(seed.GetHashCode());
  31.  
  32. for(int x = 0; x < width; x++)
  33. {
  34. for(int y = 0; y < height; y++)
  35. {
  36. map[x,y] = (psuedoRandom.Next(0, 100) < randomFillPercent) ? 1 : 0;
  37. }
  38. }
  39. }
  40.  
  41. void OnDrawGizmos()
  42. {
  43. if(map != null)
  44. {
  45. //.. Draw Grid (but we never get here, because map == null)
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement