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 uberokeer · Jun 29, 2013 at 05:51 PM · colliderprefabtriggergridrts

Creating a 68x68 grid of trigger cubes

I haven't posted here in awhile, but I need help with something. What i'm trying to do is create a grid of cubes that are invisible but represent places where i can place buildings. What i have done so far is create a prefab of a cube that is a trigger and doesn't have a mesh Renderer. But in the code i'm guessing that i would need to create a array of game objects and then create them from the prefab in a do while loop, But the problem is, I need to keep track of every cube so i can access them later. So i need to name each cube something different for instance the cube on the position would be called "cube 1x1" and then "cube 1x2" and so on for every cube. Anyone know how i would go about doing this? Thanks in advance.

Comment
Add comment
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

2 Replies

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

Answer by iwaldrop · Jun 29, 2013 at 06:18 PM

Its pretty easy, as i hope you'll realize once you read this. Use a for loop. Two, actually, with the second nested within the first. The first one will handle x positioning while the second will handle z positioning (assuming its laid out on the x,z plane).

You need to know the dimensions of the squares, and how far apart they'll be spaced. With that, you have the delta between their origins. Add this delta to either the z or x position (respective of the innermost loop you're within). Create a game object with a name of string.Format("cube {0}x{1}", x, z), add your cube controller (which should require a box collider component), scale it properly and place it. The cube controller should notify the grid controller about itself in its awake method. The grid controller can then add the cube to a list. You can now control each cube independently (via their controllers) and the grid as a whole via the grid controller.

Some nifty things you can do include sending events to cubes that neighbor a newly added cube to do some fancy stuff, and easily de/serializing the cubes via the grid.

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
2

Answer by DaveA · Jun 29, 2013 at 06:24 PM

There are things in the Asset Store that will do this, here's one: http://u3d.as/content/equilibre-games/align-editor-2/1Am There's a free one called Array Modifier, probably more like that too.

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

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

17 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

Related Questions

How to check whether gameObject is on even ground? 1 Answer

Moving kinematic rigidbody trigger against kinematic rigidbody collider 0 Answers

Trouble with triggers and colliders 1 Answer

How do you trigger a specific collider using OnTriggerEnter? 2 Answers

multiple Objects Enter OnTriggerEnter 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