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 04, 2011 at 07:52 PM · enemyspawnstringcountlength

Enemy spawner help with lengths

How can I get a count of child gameobjects by name (NOT BY TAG)? I made an enemy spawner that first looks for and counts tagged gameobjects named "ReSpawn", but then I need it to find and get a count of children in all those ReSpawns it finds with a specific name (Not Tag).

I am trying to construct a script for multiple enemy spawners. For each spawner I can drag and drop any type of enemy into a 'gameobject[]' string. Each spawner will first count how many enemies are active in the level by looking for a tag, and then if the enemy.length is below (x), it will(the idea, the part I need help with) check if the active enemies have a child with a name I manually enter through the inspector for each Spawner I place in the level.

This way I can place spawners in any area in a level, and it will spawn only the enemies I've put in its string, when its specific enemy count is down.

I hope my script is easy enough to catch the drift of my goal

     var ThisSpot : String; // what to name instantiates for this spawners area
 var Oppos : GameObject []; //drag and drop enemies I choose to intantiate here
 var OppoCount : GameObject [];
 var HowMany = 3; // how many enemies to spawn from this spawner
 var spawnSizeArea = 25;
 
 
 
 
 function Update () {
 
 OppoCount = GameObject.FindGameObjectsWithTag("Respawn");
 
 
 for ( ops in OppoCount){
 
 ops = transform.Find(ThisSpot).gameObject; // This is the problem. How do I correctly  
                                                 //get a count of child objects in 'ops' ??
 print(ops.length);
 
 if(ops.length < HowMany){ // if this specific spawners instantiates count is below 'HowMany', spawn more
 StartCoroutine ("Spawn");
 }
 }
 }
 
 
 
 function Spawn(){
 
 var length = Oppos.length-1;
 var index = Mathf.Round(length*UnityEngine.Random.value);
 curSpawn = Oppos[index]; // pick a random enemy to spawn from the 'Oppos' string each time
 
 var xz = Random.insideUnitCircle * spawnSizeArea;
 var newPosition = Vector3(xz.x,0,xz.x)+transform.position;
 
 yield WaitForSeconds(Random.Range(70,120)); // how long to wait between spawns
 
 
 var newOp : GameObject = Instantiate(curSpawn, newPosition, transform.rotation);
 
 newOp.transform.Find("fighter").name = ThisSpot; //name child object in string so you can find this specific spawners instantiates
 
 StopCoroutine("Spawn");
 }
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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Shoot Bullet Delay Enemy 0 Answers

Spawning different random objects at the same position? 2 Answers

RPC , string parameter is sent, but length is 0 1 Answer

Enemy Wave 1 Answer

Spawn Limit for enemies 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