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 miles1618 · Jun 16, 2014 at 07:52 PM · gameobjectarrayimportsimulation

Map GameObjects to Array of Positions

I have an array consisting of {x,y,z} coordinates. I would like to create a game object for each coordinate. I've been watching tutorials about importing and Instantiate but have not been able to move forward. My file type can be converted into any form necessary for import.

Have: array of 3-tuple coordinate. approximately 300 tuples.

Need: Scripting help to map a game object to each coordinate.

Comment
Add comment · Show 2
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 tanoshimi · Jun 16, 2014 at 07:54 PM 0
Share

So what's the problem exactly? Loop over the array and pass the x,y,z coords to create the Vector3 transform.position at which Instantiate() creates the object. Post your code if you are stuck.

avatar image miles1618 · Jun 16, 2014 at 08:52 PM 0
Share

$$anonymous$$y problem is simply experience level. C# is brand new to me and I have been using Unity less than a week. I'll follows those tips and once I have something I'll post the code. Thanks @tanoshimi

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by IvovdMarel · Jun 16, 2014 at 09:24 PM

 public GameObject myPrefab; // Set this variable in the inspector
 private Vector3[] objectPositions = new Vector3 {
 new Vector3(0,0,1),
 new Vector3(0,1,1)
 }; // or whatever your points in the array are
 
 private void Awake () {
 foreach (Vector3 objectPos in objectPositions) {
 GameObject myObject = Instantiate (myPrefab) as GameObject;
 myObject.transform.position = objectPos;
 }
 }

Something like that?

Comment
Add comment · Show 2 · 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 miles1618 · Jun 20, 2014 at 09:31 PM 0
Share

@Ivovdd$$anonymous$$arel .. This helped a huge amount. Thanks for taking the time to code it out.

avatar image robertbu · Jun 20, 2014 at 11:47 PM 0
Share

@miles1618 - If this answer answered your question, please click on the checkmark next to the answer to close it out. Thanks.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Checking if a position is occupied in 2D? 1 Answer

Get all other GameObjects (not the one script is attached to) 2 Answers

Adding GameObject to GameObject[] array 1 Answer

Array out of index? 1 Answer

HELP Find gameObject With tag in another array 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