© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
whiteviperx

❔ Creating a grid

Trying to create a 5 x 5 grid, but because object is 3d it shows up sideways

using UnityEngine;

public class LevelManager : MonoBehaviour
    {
    // V = vertical grid qty
    private const int V = 5;

    // H = horizontal grid qty
    private const int H = 5;

    [SerializeField]
    private GameObject tile;

    // Start is called before the first frame update
    private void Start()
        {
        CreateLevel();
        }

    // Update is called once per frame
    private void Update()
        {
        }

    private void CreateLevel()
        {
        float tileSize = tile.GetComponent<MeshRenderer>().bounds.size.x;

            {
            for(int x = 0; x < H; x++)
                {
                for(int z = 0; z < V; z++)
                    {
                    GameObject newTile = Instantiate(tile);
                    newTile.transform.position = new Vector3(tileSize * x, 0, tileSize * z);
                    }
                }
            }
        }
    }
using UnityEngine;

public class LevelManager : MonoBehaviour
    {
    // V = vertical grid qty
    private const int V = 5;

    // H = horizontal grid qty
    private const int H = 5;

    [SerializeField]
    private GameObject tile;

    // Start is called before the first frame update
    private void Start()
        {
        CreateLevel();
        }

    // Update is called once per frame
    private void Update()
        {
        }

    private void CreateLevel()
        {
        float tileSize = tile.GetComponent<MeshRenderer>().bounds.size.x;

            {
            for(int x = 0; x < H; x++)
                {
                for(int z = 0; z < V; z++)
                    {
                    GameObject newTile = Instantiate(tile);
                    newTile.transform.position = new Vector3(tileSize * x, 0, tileSize * z);
                    }
                }
            }
        }
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,828Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Creating a template
C#CC# / help
3y ago
❔ Populate a grid .NET MAUI
C#CC# / help
3y ago
Creating a .NET language
C#CC# / help
2y ago
✅ creating a CLI application
C#CC# / help
2y ago