Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

Sign in to follow this  
geckoo

sort an array

Recommended Posts

Recently, playing with enemies in my latest LD entry, I noticed that when I use an array in runtime, there is no order. As an example, using FindGameObjectsWithTag, obviously there is no logic, sorting all corresponding objects. However often we have to avoid some conflict between those objects. Another difficult issue is the fact that the player moves and its enemies too (the first now maybe will be the last soon). In my latest projects, the nearest enemy had to approach the player, then the second, the third, etc - and finaly the farthest. This way no one comes across its previous comrade in the line. So I find a way to sort an array, using a list and according a simple or complex function. In this code, I show you the method, but of course, you can improve it regarding your goal. A good stuff - a little tip ++

 

Please login or register to see this code.

Share this post


Link to post
Share on other sites

FindObjectsWithTag goes through all the objects in the scene, and returns an object if the tag is matching. So the order is the scene's hierarchy basically, not the distance of an object. Or at least, thats what I think lol

Share this post


Link to post
Share on other sites

It could be interesting to do a test :)

Writing my explanation, it were no really clear. I did some minor changes explaining code ++

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...