_EagleOwle_

Gizmo Draw Grid

Jun 24th, 2021 (edited)
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. [SerializeField] bool drawGrid = false;
  2.     [SerializeField] float gridSize = 1;
  3.     [SerializeField] float cellSize = 1;
  4.  
  5. void OnDrawGizmos()
  6.     {
  7.         if (drawGrid == false)
  8.             return;
  9.  
  10.         Gizmos.color = Color.red;
  11.  
  12.         for (int x = 0; x < gridSize + 1; x++)
  13.         {
  14.             Vector3 startPosition = new Vector3(0, 0.1f, x*cellSize);
  15.             Vector3 endPosition = new Vector3(gridSize * cellSize, 0.1f, x * cellSize);
  16.             Gizmos.DrawLine(startPosition, endPosition);
  17.         }
  18.  
  19.         for (int x = 0; x < gridSize + 1; x++)
  20.         {
  21.             Vector3 startPosition = new Vector3(x * cellSize, 0.1f, 0);
  22.             Vector3 endPosition = new Vector3(x * cellSize, 0.1f, gridSize * cellSize);
  23.             Gizmos.DrawLine(startPosition, endPosition);
  24.         }
  25.     }
Add Comment
Please, Sign In to add comment