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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by TuckerFlynn · Jun 05, 2015 at 04:12 PM · vector3listindex

Access x value in list of Vector3

I've made a list of all possible x/y coordinates with my map area:

 for(int x = 0; x <= worldWidth; x++) 
         {
             for(int y = 0; y <= worldHeight; y++) 
             {
                 //makes a list of all possible positions for tiles
                 gridPositions.Add(new Vector3(x, y, 0f));
             }
 }

I've figured how to render a tile at every position, but next I need to apply a dozen more restrictions to create a landscape. To do this I need to access the x and y values of entries in my list, and I know in javascript and it would be something like gridPosition[i].x , but I'm unsure how to get it in Unity. Thanks!

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 Hellium · Jun 05, 2015 at 04:23 PM 0
Share

Have you even try to do what you think ??

avatar image TuckerFlynn · Jun 09, 2015 at 06:26 PM 0
Share

I hadn't, but now that I've actually learned a bit more about C# I realize a lot of it is identical to Javascript, which will save me a lot of reading from here out.

3 Replies

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

Answer by _alphaBeta_ · Jun 05, 2015 at 04:40 PM

From your example, gridPositions would appear to be of type Vector3, so you should be able to do as you suggested. ".x" after the Vector3 variable will return the x component as a float. You may want to have a look at the Vector3 scripting reference for this instance.

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
0

Answer by Foulcloud · Jun 06, 2015 at 03:38 PM

I think you answered your own question. You will need to declare gridPositions as an array and I usually set the size before hand.

Vector3[] gridPositions;

gridPositions = new Vector3[worldHeight];

for(int x = 0; x <= worldWidth; x++) ..... rest of code

Then to access x value:

tempFloat = gridPosition[I].x;

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
0

Answer by tanoshimi · Jun 05, 2015 at 04:35 PM

You've called your list gridPositions, so it's gridPositions[i].x, not gridPosition[i].x.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

instantiate problem help? 1 Answer

Vector3[]? 1 Answer

What's the proper way to see if a Vector3 List index is null? 1 Answer

Getting Vector3 from random item in List 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