Advertisement
MaximilianPs

WallBuilder

Jun 26th, 2021
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. private GameObject WallBuilder(int x, int z, Transform parent)
  2.     {
  3.        // Debug.Log(x + " " + z);
  4.  
  5.         GameObject wall;
  6.         float angle = 0f;
  7.  
  8.         bool corner = false;
  9.  
  10.         if (x == 0 && z == 0)                               // Bottom Left
  11.         {  
  12.             corner = true;
  13.             angle = 90;
  14.         }
  15.         else if (x == 0 && z == townSize - 1)               // Top Left
  16.         {
  17.             corner = true;
  18.             angle = 180;
  19.         }
  20.         else if (x == townSize - 1 && z == 0)               // Bottom Right
  21.         {
  22.             corner = true;
  23.             angle = 0;
  24.         }
  25.         else if (x == townSize - 1 && z == townSize - 1)    // Top Right
  26.         {
  27.             corner = true;
  28.             angle = 270;
  29.         }
  30.         else if (x == 0 && z > 0)                           // Walls Left
  31.         {
  32.             corner = false;
  33.             angle = 180;
  34.         }
  35.         else if (x == townSize -1 && z > townSize -1)       // Walls Right
  36.         {
  37.             corner = false;
  38.             angle = 180;
  39.         }
  40.         else if (x > 0 && z == townSize -1)                 // Walls North
  41.         {
  42.             corner = false;
  43.             angle = 270;
  44.         }
  45.         else if (x > 0 && z == 0)                           // Walls  South
  46.         {
  47.             corner = false;
  48.             angle = 90;
  49.         }
  50.  
  51.         // it's a corner
  52.         if (corner)
  53.         {
  54.             wall = Instantiate(wallCorner[Random.Range(0, wallCorner.Length - 1)], parent);
  55.             wall.transform.position = gridNodes[x, z];
  56.             wall.transform.rotation = Quaternion.Euler(0, angle, 0);
  57.         }
  58.         else
  59.         {
  60.             wall = Instantiate(walls[Random.Range(0, walls.Length - 1)], parent);
  61.             wall.transform.position = gridNodes[x, z];
  62.             wall.transform.rotation = Quaternion.Euler(0, angle, 0);
  63.             wall.name = wall.name + ":" + x +","+ z;
  64.         }
  65.  
  66.         return wall;
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement