Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 superventure · Aug 03, 2011 at 08:04 PM · spawnmultiplefindnamelength

Help with a spawner script

Edit

How can I get a length of specific active gameobjects by a name instead of by tag in an update function? I know it takes longer, but I would rather that than make a ton of tags to search for. Specifically, I tag all of my enemy gameobjects "ReSpawn".

var locationOne:String; var enemyCount: GameObject[];

enemyCount = FindGameObjectsWithTag("ReSpawn")

How do I find and get a length all ReSpawns that might have a child object named 'locationOne'?

I need to continually check if ReSpawns found witha 'gameObject locationOne'.length < (x) or not.

Thanks for any help

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
0

Answer by DaveA · Aug 03, 2011 at 09:54 PM

Try to avoid using any 'Find' routine in Update. Best do that in Start and then manage the list if things are added/removed during play. Also try to use lower case to begin variables and upper case to begin functions.

Would you be able to use layers to help organize things?

Also consider http://unity3d.com/support/documentation/ScriptReference/Object.FindObjectsOfType.html

OppoCount will be an array of objects with that tag, so you can look for the name on each one like:

 foreach (op in OppoCount)
   if (op.name == "ThisSpot")
     .. do something..

 or

 foreach (op in OppoCount)
   foreach (t in op) // check children of the found items
     if (t.name == "ThisSpot")
       .. etc..

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 superventure · Aug 05, 2011 at 05:24 AM 0
Share

The second foreach example gives me error messages that t in op is not enumerable. The examples are directions for doing something to each of the children it finds, not exactly 'counting' them. I need a length to check, I don't need to actually DO anything to the gameobjects with the names I'm looking for. I'm trying to avoid making a whole bunch of tags.

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

Enemy spawner help with lengths 0 Answers

Multiple scripts with the same name issue 1 Answer

JS, get child 2 Answers

List all prefabs in project with a specific name 1 Answer

Spawn Multiple Monsters 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