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 unityfan4ever · May 08, 2014 at 06:37 PM · 2dtexturegridboardgame

creating 2d table\chess board\2d array

Hi guys! I want to create a simple 2d chess-like board, I want it to be dynamic i.e. each "square" can change color, and board size can grow (for example from 10x10 to 12x12), and I also want to be able to identify if a specific "square" got clicked on.

I have read a lot of articles on the internet, and couldnt find a clear answer- from what I read, such a board would cause performance issues. From what Ive understood there are 3 options: 1. create a grid and create cubes on it - can someone please further explain what exactly is a "grid" in unity? 2. use 2d-array and manipulate it to show the squares - dont really know how 3. create 10x10 rects a locate them - can cause performance issues?

Can someone please help me understand what is the prefered option, and maybe guide me of where to start?

Thanks

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 Pyrian · May 08, 2014 at 07:02 PM 0
Share

I don't think you're going to hit performance issues at 10x10 (100) or 12x12 (144). 100x100 (10,000) might be a different matter.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by gfallasc · May 08, 2014 at 10:00 PM

Hi, I don't see any problem creating 2d arrays.

  1. If by a grid means using a single mesh for the whole table, it's very hard for the logic game using a single mesh.

  2. Yes, you could use a "2D array" or matrix which easily could be manipulated by example using a List (C#), and that list could look like this: List< SquareClass[] > my2DArray supossing the "SquareClass" is a script for each square block (I don't think there would be a perfomance issue using something like this).

  3. For the point three, I think that couldn't be the better option to implement the game, because if you're using a class behavior for each block, then each block could easily manage the input, and dynamically change the color (you could change the material).

Comment
Add comment · Share
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
1

Answer by hippysniper · May 08, 2014 at 10:14 PM

no you will not get any performance issues with an array that size or that little objects, it may take a second or less to instantiate but it will not effect the game in anyway. to give you an example i recently made a bomber man game which would instantiate boxes in accordance with the location. the player could dynamically edit the map and watch the boxes spawn on screen we only started to experience lag issues when the player made a 500x500 plus array for the level but once instantiated the game ran well.

as far as your question about a grid i am assuming that they are simply talking about the array that you will place you game objects into.

the best way to get started would to do some practice on assigning and manipulating small arrays. I would start with this method (i have not tested the code as i am on my phone =) )

 private GameObject[] grid; 
 public Gameobject block;
 public float blockSize;
 
 
 void Start(){
 grid = new grid[2,2];
 }
 
 void Update(){
 
 for(int i = 0; i <grid.length; i++){
   for(int j = 0; j <grid.height; j++){
    temp = (GameObject) instantiate(Block, new vector3(i *  blockSize, j * blockSize,0),quternion.identity);
    grid[i,j] = temp;
 
 
   }
 }
 }
Comment
Add comment · Show 1 · Share
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 unityfan4ever · May 11, 2014 at 09:23 PM 0
Share

Hi Thanks for the code, I played with it a bit, and figured out how to create new objects.

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

23 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 avatar image avatar image avatar image

Related Questions

Highlighting tiles on a hexagonal grid 1 Answer

Creating a 2D Movement Grid 0 Answers

Texture grid displayed oddly when width =/= height 1 Answer

Paint Grid Texture 1 Answer

Lines are disappearing and merging as I zoom out 2 Answers


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