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 CrazyPizza · Jan 21, 2014 at 05:13 PM · androidgridtilegrid based game

Create a grid on a cube?

Hello! :) I'm working on a game which needs a grid. I have a 10x10 flat cube which I use as my "grid area", what I want to do is creating a grid inside this cube which resizes according to a parameter. For example if I want a 5x5 grid, the grid area will consist of 25 cubes of the same size (like a normal grid d'oh).

I have a simple script that creates a grid and instatiates objects according to the grid: var prefabCount=0; var tGridX=0; var tGridY=0; tubesArray=new GameObject[gridY,gridX];

 var posY=-1.0;
 for (var y= 0; y< gridY; y++){
     
     for (var x=0; x<gridX; x++){
         selectPrefab(gridChars[prefabCount]);
         var pos=Vector3(x, posY, 0)*spacing;
         var temp= Instantiate(myPrefab, pos, Quaternion.identity);
         tubesArray[y,x]=temp;
         tubesArray[y,x].GetComponent(CubeProperties).setPosition(y,x);
         prefabCount++;
         
         }
     posY=posY+1.0; 
     }
     
 }

This works but I have to set Y and X positions and prefabs sizes to fit the screen (it's an Android project btw). I need a better grid system which allows me to change the size of the prefabs I have to instantiate, to fit the square tile size of the grid without changing it manually everytime.

It's way more difficult to explain than I tought :( I tought I could do just like in real life where i just take the size of the area (10x10) and divide it by 3 if i want a 3x3 grid; so each grid's tile would be of around 3,33, and set the prefab size to that; but it doesn't work D:

Any suggestions? Solving this problem would boost my project a lot!

PS. Forgot to say that the prefabs are just square sized gameobects sprites, don't know it is useful

Comment
Add comment · Show 3
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 CrazyPizza · Jan 22, 2014 at 11:08 AM 0
Share

To better explain what I want to do: here's an image of flow free, I want to do the exact same thing (the play area stays the same, the size of squares is reduced to create a bigger grid), but I also need a way to scale down a sprite gameobject to fit the square size and instantiate it.

alt text

avatar image robertbu · Jan 22, 2014 at 11:11 AM 0
Share

$$anonymous$$ight be easier to leave the grid sizes the same and change either the camera's field of view (if you are using a perspective camera) or the camera's orthographic size (orthographic camera) to allow the squares to fit the view.

avatar image CrazyPizza · Jan 22, 2014 at 11:14 AM 0
Share

That could work indeed! I'm using an orthographic camera. I'll go with this solution for now thanks.

I'd still like to know how something like flow free grid area is made tho

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

18 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

Related Questions

Grid and or Tile System 0 Answers

How can I compare two tilemaps by color? 1 Answer

How to stack components on a Tile/Tilemap 0 Answers

How to create a rotating tiles with walls on edges of tiles? 0 Answers

How do you find adjacent tiles of the same type in grid array [x,y].type == [x+1,y].type 0 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