- Home /
 
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.
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));
 
              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 :)
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
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.
Your answer
 
             Follow this Question
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