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 highpockets · Feb 23, 2013 at 06:38 AM · arraypositionarraysvectorfind

How do you find one Vector's position of an Array?

Hello,

Forgive me if this has already been asked, but I couldn't find anything.

I have an array of Vector2's and at each one of those Vector positions there may or may not be a game object. The idea is that once one of these game objects is hit with RaycastHit I want to compare it's transform position with the list of Vector2's in the array. When I return a match, then I've done exactly what I want to do, but the only way that I,ve been able to do that so far is manually writing:

if( hitGameObject == myVectorTwoArray[ 3,4 ]; )

I'm not overly keen on writing down each array, not just because of the time it takes, but also because my scenes will vary in size and some will need a larger list of arrays. So, I would have to rewrite the code for every scene.

Does anyone know how to do this? Or is it even possible?

I apologize if this is something simple.. I have just over a month of programming exp.... Total Noob!!

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

1 Reply

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

Answer by robertbu · Feb 23, 2013 at 06:49 AM

I'm visualizing a minefield here. Comparing Vector2 is problematic since they are composed of floats. One way to solve this issue is to push information down to the game objects. Record the row/col information in a script attached to each game object. When you get a hit, you can immediately find the array entry.

I'm not sure what information you are storing at the array positions, but you might push that down to the game objects as well so during a hit you don't have to refer to the array at all.

When you say "writing down each array," I thinking that you are doing a comparison with hard-coded values like you have in your question. If you don't already know, nested for loops will solve this more simply.

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 highpockets · Feb 23, 2013 at 08:09 AM 0
Share

Thanks for the advice robertu.

I'll try out your suggestions.

I created the array with nested loops, I just meant that I would have to write out an if-statement for comparing every array location with the game object's transform position.

Anyways, since you mentioned the nested loop, you got me thinking that I can accomplish what I need by storing the array position in the game objects like you said while the nested for loop is doing it's thing.

No $$anonymous$$efield, but it sure sounds like it hey!!!

Thanks again!

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I find the position of an element in an array? 3 Answers

Unity3D - Playback object array of position (with dynamic velocity) 0 Answers

How do I check the distance between multiples objects in an array from the player? 4 Answers

How do I instantiate same tag/name GameObjects with an array 1 Answer

How to get a vector3 (postion) 1 unit away from another in the direction of a 3rd vector3? 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