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 o2Neoxide · Apr 21, 2015 at 12:04 PM · javascriptdestroyreloadfix

What's Wrong? 2 Problems

I am currently trying to make a script that makes the Player die after colliding with a Plane/Object but when I test the game with the script in the Plane/Object, there is an error:

ApplicationException: Argument is not enumerable (does not implement System.Collections.IEnumerable). Boo.Lang.Runtime.RuntimeServices.GetEnumerable (System.Object enumerable)

The script is as follows:

 function OnTriggerEnter(other : Collider){   
        if(other.gameObject.name == "Player"){ 
               GameObject.Destroy(other.gameObject); 
              for(var child : Transform in transform.gameObject){ 
                             GameObject.Destroy(child.gameObject);  
                  }                                                                            
               Debug.Log("Player was brutalized"); 
        }
  }
  

I also have another problem with a Reload Level script I put in my game scene. It generates a 'Restart' GUI button which reloads the level, but when I click it, the light in the scene turns darker.

The script is as follows: function OnGUI(){

  if ( GUI.Button( Rect( 1, Screen.height-25, 75, 25 ), "Restart" )) {
  
  Application.LoadLevel(Application.loadedLevel);
  
  }
  
  }

If you could help me fix these two problems, I would appreciate it greatly.

Thanks.

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
1
Best Answer

Answer by hbalint1 · Apr 21, 2015 at 12:53 PM

instead of this:

 for(var child : Transform in transform.gameObject){ 
     GameObject.Destroy(child.gameObject);  
 } 

you should write this:

 var children = new List<GameObject>();
 
 foreach (Transform child in transform)
    children.Add(child.gameObject);
 
 children.ForEach(child => Destroy(child));
Comment
Add comment · Show 8 · 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 hbalint1 · Apr 23, 2015 at 07:59 AM 0
Share

Hello. You can try this method, it's simpler:

 foreach (Transform child in transform) {
      GameObject.Destroy(child.gameObject);
 }

Let me know if it works, so I can update my answer :)

avatar image o2Neoxide · Apr 23, 2015 at 08:01 AM 0
Share

Haha. Thanks hbalint1, I wasn't able to test it yesterday, so I've just come on to test out your first fix. I'll get to you soon :D But thanks anyways. I'm really new to coding, do you possibly know any good C++ tutorials. I don't really $$anonymous$$d if it takes ages. :D

avatar image hbalint1 · Apr 23, 2015 at 08:07 AM 0
Share

are you using C++ not C#?

avatar image o2Neoxide · Apr 23, 2015 at 08:08 AM 0
Share

Hah, woops, got it mixed around. Using C#. But this script is Javascript I believe. But I would like to learn either script, whichever is best.

avatar image o2Neoxide · Apr 23, 2015 at 08:17 AM 1
Share

Thanks BroVodo :D

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Instantiate prefabs before it comes into view 0 Answers

Prevent countdown from reloading every time a new scene is loaded 1 Answer

Can someone explain the destroy () command? 1 Answer

Make the animation play at the start of the time waited, not the end of it? 1 Answer

Destroy cube on collision 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