Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Exeneva · Apr 17, 2014 at 04:57 AM · tilesboardgame

Filling a board with tiles, with separation

I'm creating a basic prototype of something I have in mind, a sort of board game. Here's a picture if you're interested: http://i.imgur.com/WVck6MY.png

Each of these tiles is a separate game object right now just to show the setup. I know I can use two for-loops to place a single tile multiple times onto the board instead of having tons of identical separate game objects, but I have trouble wrapping my head around how to create 'gaps' between each tile so they're not all squished together (check my picture and you'll see there is a noticeable gap between each tile). Any help on how to generate this via code is appreciated.

I have a GameManager empty object with the following script:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class GameManager : MonoBehaviour {
 
     public GameObject TilePrefab;
     List <List<Tile>> board = new List <List<Tile>>();
 
     public int maxRows = 4;
     public int maxCols = 5;
 
     // Use this for initialization
     void Start () {
         generateBoard ();
     }
 
     // Update is called once per frame
     void Update () {
 
     }
 
     void generateBoard ()
     {
         board = new List<List<Tile>> ();
 
         for (int i = 0; i < maxRows; i++)
         {
             List <Tile> row = new List<Tile>();
             for (int j = 0; j < maxCols; j++)
             {
                 Tile tile = ((GameObject)Instantiate(TilePrefab, 
                               new Vector3(i - Mathf.Floor(maxRows/2),0, -j + Mathf.Floor (maxCols/2)), 
                               new Quaternion(new Vector3()))).GetComponent<Tile>();
                 tile.boardPosition = Vector2(i,j);
                 row.Add (tile);
             }
             board.Add (row);
         }
     }
 }

The tile class is basically empty, except for the default statements Unity provides and this line:

 public Vector2 boardPosition = Vector2.zero; 

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Apr 17, 2014 at 05:07 AM 0
Share

The easiest way to solve your problem is to leave your code the way it is and reduce the size of your prefab. Placing your objects on integer positions can simplify other code, so if at all possible, leave your code alone.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make a player move along a fixed route 1 Answer

Random Modular Hex Board for board game 1 Answer

How can I find an adjacent tile, if the tiles vary in shape and size? 1 Answer

creating 2d table\chess board\2d array 2 Answers

HELP!!! This NullReferenceException won't go away! :( 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges