Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 NE07HEKIN6 · Sep 02, 2011 at 01:08 PM · instantiategridmatrix

Create a grid of transform instances

I really need to do this, but im pretty new programing so i dont know where begin. What i need is create a grid with colums and rows to instantiate a series of prefabs on scene on determinate distance, and be able to put and change them within the inspector. I was thinking about some loop var, but i cant figure how to do it. Aprecciate so much your help.

alt text

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
0
Best Answer

Answer by save · Sep 02, 2011 at 01:13 PM

The Manual page on Instantiate has sample code how to do this.

Comment
Add comment · Show 3 · 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 NE07HEKIN6 · Sep 02, 2011 at 01:49 PM 0
Share

One only problem, this is good to instantiate the same object, do you know how to make it to instantiate prefabs from an array?? Thanks again

avatar image save · Sep 02, 2011 at 02:09 PM 0
Share

What does the array look like? Do you have different objects for every grid tile, objects that repeat or objects that is defined by you where they should be? How many objects are there?

Basically just bring that array (if you have it constructed) into the for-loop and go wild with it (if(objArray[i]), if(i%5) and so forth). :-)

avatar image NE07HEKIN6 · Sep 02, 2011 at 02:18 PM 0
Share

they are prefabs that make the scenary of the game, every one is put in a number on the array, 1, 2, 3, so on, so if you change a prefab you can modify the scenary, so are some prefabs that are repeated and some that have no repetition. The array looks like the drawing i put up, its a x*y array. I can do this by hand, but i think it would be nicer to find out a code to instantiate prefabs on the inspector in an automatic way.

avatar image
0

Answer by NE07HEKIN6 · Sep 02, 2011 at 02:25 PM

I already did it, was simple after all, i post it in case someone needs it

var cube : Transform[];

function Start () {

for (var y = 0; y < 5; y++)

{ for (var x = 0; x < 5; x++)

{ for (var z = 0; z < x*y; z++) { var cube = Instantiate(cube[z], Vector3 (x, y, 0), Quaternion.identity); } } } }

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 maxmadman · Jul 02, 2014 at 10:31 PM 0
Share

Thanks for sharing. This might answer my need. I am using instantiate prefab, but I am not sure if it can control the texture as flexible as I wanted to be.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Draw Texture in a grid like Trainyard 2 Answers

How to instantiate the prefabs on grid in Unity? 1 Answer

Instantiate objects in a new position into a grid 1 Answer

Improving Grid Algorithm 1 Answer

Need Help With 2D Array Grid Position Tracking With JavaScript 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