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 awesomemrd · Mar 26, 2013 at 05:52 PM · aispawnspawning

Why won't my AI spawning script work?

It spawns 4 skeletons the first round, and everything works, but then in the second round nothing happens. What is wrong?

 #pragma strict
 var prefab : Transform;
 var gos : GameObject[];
 var dead : GameObject[];
 var roundText : GUIText;
 var round : int = 1;
 var maxEnemies : int = 4;
 var roundStart : boolean;
 var count : GameObject;
 var player : GameObject;
 var script : boolean;
 function Start ()
 {
     count.GetComponent(Countdown).enabled = false;
 }
 
 function Update () 
 {
     gos = GameObject.FindGameObjectsWithTag("Enemy");
     dead = GameObject.FindGameObjectsWithTag("Dead");
     player = GameObject.FindWithTag("Player");
     script = player.GetComponent(PlayerHealth).isDead;
     Round();
     roundText.text = "Round" + round.ToString();
 }
 
 function Round()
 {
     if(gos.length < maxEnemies && roundStart == false && script == false)
         {
             roundStart = true;
             for (var i : int = 0;i < 4; i++)
              {
                 Instantiate (prefab, Vector3(i + 2 + 1048.741, 4, 1596.766), Quaternion.identity);
             }
         }
     if (dead.length == maxEnemies)
     {    
         round += 1;
         maxEnemies += 2;
         for(var k = 0 ; k < dead.length ; k ++)
         {
             Destroy(dead[k]);    
         }
         count.GetComponent(Countdown).enabled = true;
         roundStart = false;
     }
 }
 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by KMKxJOEY1 · Mar 27, 2013 at 04:08 PM

firstly:

roundText.text = "Round" + " " + round;

lol why not just

roundText.text = "Round" + round;

also round is not a string so you must use a ToString() like this:

roundText.text = "Round" + round.ToString();

As for your problem, where are you turning roundStart back on?

Comment
Add comment · Show 2 · 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 awesomemrd · Apr 01, 2013 at 11:45 AM 0
Share

Thanks! I turn it on here:

 if(gos.length < maxEnemies && roundStart == false && script == false)
 {
 roundStart = true;
 for (var i : int = 0;i < 4; i++)
 {
 Instantiate (prefab, Vector3(i + 2 + 1048.741, 4, 1596.766), Quaternion.identity);
 }
 }


and then i make it false once they are all dead here:

 if (dead.length == maxEnemies)
 {
 round += 1;
 maxEnemies += 2;
 for(var k = 0 ; k < dead.length ; k ++)
 {
 Destroy(dead[k]);
 }
 count.GetComponent(Countdown).enabled = true;
 roundStart = false;
 }
avatar image awesomemrd · Apr 01, 2013 at 11:54 AM 0
Share

It should work....

avatar image
0

Answer by BlackWingsCorp · Mar 27, 2013 at 02:22 PM

Based on your code it looks like you tagged the skeletons gameobject multiple time as"Enemy" then "Dead" which is impossible because unity doesn't allow you to do that. (Unless you trick it with code) so the length of your gos array never goes under 4 because even when the skeletons are down they don't get destroyed. I assume you have an enemy health script so add something like this to it:

 if(health == 0){
 Destroy(this.gameObject)
 }

Hope it helps.

Comment
Add comment · Show 2 · 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 awesomemrd · Apr 01, 2013 at 11:41 AM 0
Share

Actually what happens is I kill each of them and then when they're all dead it deletes them. That way I can have a death animation and they stay in the ground until the round is over.

avatar image awesomemrd · Apr 01, 2013 at 11:42 AM 0
Share

Thanks though!

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AI spawning areas. What are the ways to make them? 1 Answer

How to have a cloned/duplicated enemy react the same way the original does? 1 Answer

i'm trying to spawn enemies and it goes well but when i'm trying to scale them it doesn't sync i used [ClientRpc] and it didn't work 1 Answer

How to Spawn after checking if the clones are destroyed. 1 Answer

Does using both Update() and a coroutine cause respawning problems? 0 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