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 bigrig91 · Feb 17, 2015 at 02:25 PM · instantiateienumerator

removing instantiated game objects after time

Hey guys I'm super new to coding and want to learn. I am trying to make a simple(not so simple) 2D android game learning as I go. I am currently stuck where the instantiated gameobjects are not being removed after a certain time period. I don't have any errors or warnings so I at a loss what to do next although I suspect maybe it's got somehting to do with this code

IEnumerator removeoldweedfromlist(List list) { yield return new WaitForSeconds (4.0f); list.RemoveAll (item => item = null);

I have been trying to figure this out for hours and have realized it must be the item => item part?

Anyway, I have attached the screen shot of the entire script as well.

thank you in advance I applaud anyone who knows anything about coding. alt text

ee.png (58.1 kB)
Comment
Add comment · Show 4
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 bigrig91 · Feb 17, 2015 at 02:16 PM 0
Share

Why do you never post code as a screenshot??

avatar image bigrig91 · Feb 17, 2015 at 02:23 PM 1
Share

oh ok good to know i'll keep that in $$anonymous$$d in the future

here is the code

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Createblueweed : $$anonymous$$onoBehaviour {
     public GameObject initialblueweed;
     public float timefornewweed;
     public float currentbluetime = 0.0f;
     public Vector3 initialblueweedposition;
     List<GameObject> newblueweed = new List<GameObject>();
     public GameObject prefab;
 
 
 
     void Start () {
         newblueweed.Add (initialblueweed);
         initialblueweedposition = initialblueweed.transform.position;
     }
      
     void Update () {
         createnewblueweed ();
         StartCoroutine (removeoldweedfromlist (newblueweed));
 
     }
 
         
 
     void createnewblueweed() {
          if (Time.time - currentbluetime > timefornewweed) {
         currentbluetime = Time.time;
         //creating a new instance of a new blue weed 
         newblueweed.Add(Instantiate (newblueweed[newblueweed.Count - 1], new Vector3 (initialblueweedposition.x, initialblueweedposition.y + randomYoffset(), initialblueweedposition.z), Quaternion.identity) as GameObject);
         newblueweed[newblueweed.Count - 1].name = "newblueweed" + newblueweed.Count;
         }
     }
     
     float randomYoffset() {
             return Random.Range (-4f, 4f);
 
     }
 
     IEnumerator removeoldweedfromlist(List<GameObject> list) {
         yield return new WaitForSeconds (4.0f);
         list.RemoveAll (item => item = null);
 
     }
 
 
      
 
   }
avatar image CHPedersen · Feb 17, 2015 at 02:26 PM 0
Share

No worries. :) Published the question now.

Just for convenience, could I get you to please edit the comment and mark the section with the code and hit the format (1010101) button a couple times until it formats correctly?

avatar image bigrig91 · Feb 17, 2015 at 02:30 PM 0
Share

edited, that looks much better

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by bigrig91 · Feb 17, 2015 at 03:40 PM

super simple thank you very much

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

Instantiate an object as soon as another object is destroyed 2 Answers

Custom class with coroutine can't be added using the "new" keyword 1 Answer

How to wait scene to load if using IEnumerator Start()? 0 Answers

Endless runner obstacles spawning problem 1 Answer

IEnumerator not looping correctly? 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