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 matta9001 · Sep 08, 2014 at 08:59 PM · javascript

Delete last 5 Clones so only 5 exist

Im making a game where you fly through rings and collect the rings and right after another clone of the ring spawns in a random area. I have that all working and good, but i could just make it so that the clones are just spawning over and over but if someone did really really good they could really lag out the phone with lots and lots of clones. So i want to make it so that you collect 5 rings, and then the last ring gets destroyed, so that there are still 5 clones but 5 at most or something. I was going to have a script on every clone that adds one to every clone and if a integar gets to be over 5 it would get deleted, but i wasn't able to get it to work. So how do you delete the clone so there is only 5?

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

2 Replies

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

Answer by Cherno · Sep 08, 2014 at 11:49 PM

Sounds like you could just keep a Generic List of the gameObjects. When you create a new ring, you add it (it will get added to the end of the list), and in Update you check if there are more than 5 rings in the list; If yes, then you destroy enough rings so the Count is 5 again, starting from the 0 index of the list, then +1, and so on. The list will then have only the five most recently added rings in it.

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 matta9001 · Sep 09, 2014 at 12:17 AM 0
Share

I mean i understand the concept, but i need like some API to know how to do what your trying to say

avatar image Cherno · Sep 09, 2014 at 12:34 AM 0
Share

For lists, arrays and such, I highly recommend this detailed article:

http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use%3F

avatar image
0

Answer by Kiwasi · Sep 08, 2014 at 11:56 PM

The simplest way to do this would be to have a collection with a capacity of five. Add GameObjects to the collection as they are created. When the collection is at capacity then instead of adding a new one move the oldest element.

Essentially what you want is a modified object pool. Google object pool for some good solutions.

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

24 People are following this question.

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

Related Questions

A node in a childnode? 1 Answer

Flying AI Planes 0 Answers

Iphone Unity and Best book . 1 Answer

Unity webplayer crashing browser when it is loaded and unloaded into a page using JavaScript 0 Answers

Sync Text with audio 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