Advertisement
plattina

Chesssboard Unity

Mar 16th, 2022
911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. public class DrawChessBoard : MonoBehaviour
  2. {
  3.     public GameObject square;
  4.     void Start()
  5.     {
  6.         for (int x = 0; x < 8; x++)
  7.         {
  8.             for (int y = 0; y < 8; y++)
  9.             {
  10.                 bool isLightSquare = (x + y) % 2 != 0;
  11.  
  12.                 var squasreColor = isLightSquare ? Color.white : Color.black;
  13.                 Vector3 position = new Vector2(-3.5f + x, -3.5f + y);
  14.  
  15.                 square.GetComponent<SpriteRenderer>().color = squasreColor;
  16.                 var obj = Instantiate(square, position, Quaternion.identity);
  17.                 obj.name = $"Position: {x}-{y}";
  18.             }      
  19.         }
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement