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.

  • 0
Sign in to follow this  
CakeMonsTv

Adding objects to a list in specific order

Question

How would I add objects to a list in specific order? I first want to add object with name "1" then "2"... (look gyazo image below)

Right now I made it so that all those objects will be added but not in that order.

 

-----------------------------------------------------------------------------------------

 

 public List<GameObject> places = new List<GameObject>();

 

    foreach(GameObject placeSearch in GameObject.FindGameObjectsWithTag("place" + team)){
        places.Add(placeSearch);
        }

 

-----------------------------------------------------------------------------------------

Gameobjects to add in order from lowest name number to the highest

Please login or register to see this link.

 

Thanks

Edited by CakeMonsTv

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

what are you making there?

you simply populate list with data and then sort by your liking.

 

if you want to go hard way and manually add objects in list by order, then:

places.Insert(index, go);

Share this post


Link to post
Share on other sites

  • 0
Please login or register to see this quote.

I did made a quick look into those articles and i didnt find anything usefull. I thought i could find a more elegant solution like simply searching for object name 1 then 2 then  3 etc. However I will give sorting a more in depth look if I dont find that solution. 

Edited by CakeMonsTv

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

I Actually went for  a totally different approach now. No sorting or anything, just instantiating objects one by one and adding them in list iin that order. (I had to do this sooner or later, since my project required it). Thanks for your time anyway.

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
Answer this question...

×   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...