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 bodomchild0926 · Mar 20, 2011 at 04:45 PM · loopfor-loopexception

Getting an error with my for/in loop!

I am trying to initiate a health drop when a particle collision takes place. I am trying to use a for/in loop to reference each possible collider and I am obviously doing something wrong. My code is:

function OnParticleCollision (other : GameObject)
{
 for (var zombie : GameObject in GameObject.Find("MainCamera").GetComponent("zombieArray"))
 {
  if (other == zombie)
  {
    ...other code...
  }

When run and a particle is shot I get this error on the line starting the for/in : ApplicationException: Argument is not enumerable (does not implement System.Collections.IEnumerable). Boo.Lang.Runtime.RuntimeServices.Error (System.String name) Boo.Lang.Runtime.RuntimeServices.GetEnumerable (System.Object enumerable) UnityScript.Lang.UnityRuntimeServices.GetEnumerator (System.Object obj) vomitHit.OnParticleCollision (UnityEngine.GameObject other) (at Assets/Scripts/vomitHit.js:29)

Any help is very much appreciated!

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

3 Replies

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

Answer by Skjalg · Mar 20, 2011 at 05:21 PM

Your for-loop is trying to loop 1 component, not many. You need to use GetComponents instead of GetComponent:

function OnParticleCollision (other : GameObject)
{
 for (var zombie : GameObject in GameObject.Find("MainCamera").GetComponents("zombieArray"))
 {
  if (other == zombie)
  {
    ...other code...
  }
}

On a side note:

You should declare your Array of objects as its own variable before you loop them to increase performance and readability.

Comment
Add comment · Show 1 · 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 bodomchild0926 · Mar 20, 2011 at 05:39 PM 0
Share

Thank you for your help, I have no errors now but the collision won't register now for some reason..is there anything you may be able to think of that could help me out again?

avatar image
0

Answer by efge · Mar 20, 2011 at 05:25 PM

For performance reasons you could also use Camera.main instead of GameObject.Find("MainCamera").

Comment
Add comment · Show 1 · 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 bodomchild0926 · Mar 20, 2011 at 05:40 PM 0
Share

thanks I will do that

avatar image
0

Answer by bodomchild0926 · Mar 20, 2011 at 06:00 PM

I now have no errors now but the collision won't register now for some reason..is there anything anyone may be able to think of that could help me out again?

Comment
Add comment · Show 1 · 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 Skjalg · Mar 21, 2011 at 09:42 AM 0
Share

I'd suggest you make a separate question for this, where you tell more in depth about your problems.

But to maybe this will help you:

Description OnParticleCollision is called when a particle hits a collider.

This can be used to apply damage to a game object when hit by particles. This message is sent to all scripts attached to the WorldParticleCollider and to the Collider that was hit. The message is only sent if you enable sendCollision$$anonymous$$essage in the inspector of the WorldParticleCollider.

Specifically the last part: "The message is only sent if you enable sendCollision$$anonymous$$essage"

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

No one has followed this question yet.

Related Questions

for loop problem,problem with for loop 1 Answer

x=x Assignment made to same variable 3 Answers

How to have a loop run itself again if returned value is a known exception, with a new return value. 1 Answer

What's wrong with this for loop? 1 Answer

Difference between if statement, while and for loop? 4 Answers


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