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 /
  • Help Room /
avatar image
0
Question by Codelyy · May 23, 2016 at 12:24 AM · c#spawningfor-loopenemyaicopies

Multiplying the same enemy

I'm trying to create a function that will multiple my enemy by a chosen amount. I made this:

 void DoubleTeam(int multipleAmount)
     {
         for(int i = 0; i <= multipleAmount; i++)
         {
             if(spawnedRight)
             {
                 spawnedRight = false;
                 GameObject bossCopyPrefab = Instantiate(bossCopy, new Vector3(transform.position.x + positionAmountRight, transform.position.y, transform.position.z),Quaternion.identity) as GameObject;
                 multipliedSelfs[i] = bossCopy;
                 positionAmountRight++;
             } 
             else if(!spawnedRight)
             {
                 GameObject bossCopyPrefab = Instantiate(bossCopy, new Vector3(transform.position.x - positionAmountLeft, transform.position.y, transform.position.z),Quaternion.identity) as GameObject;
                 multipliedSelfs[i] = bossCopy;
                 positionAmountLeft++;
                 spawnedRight = true;
             }
         }
     }

And I'm calling the function just for testing reasons like this:

 case EyeBallStates.NonAggro:
                 if(!test)
                 {
                     DoubleTeam(2);
                     test = true;
                 }
             break;

I'm not sure what I've done wrong but what the function is meant to do is spawn a copy of the enemy, move it to the right side and add it to an array. Then spawn another copy but move it to the left side and add that GameObject to the same array till it's spawned the chosen amount.

What it really does is keeps spawning copies to the right side past the chosen amount so it will make more then 30 copies or something when I only want two. It also doesn't seem to spawn them to the left side of the main enemy like it should, only the right side unless i set the spawnedRight variable to false.

Does anyone know why it's doing this?

Comment
Add comment · Show 1
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 Mimumu84 · May 23, 2016 at 04:17 AM 0
Share

So you want to create this effect: $$anonymous$$ey: * = Spawned enemy + = $$anonymous$$ain enemy A = Arrow to next step

          (3)      *  +  *
                      A
          (2)         +  *
                      A
          (1)         +
         

For line 3, you may want to change that to:

  for(int i = 0; i <=  multipleAmount; i++)             // From this
 
 for(int i = 0; i < multipleAmount; i++)                // To this
 
 

Furthermore, you may want to check if your function is called ONC$$anonymous$$ At times, I have encountered where my function was called multiple times due to placing it in the Update().

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

144 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Wait until a key is pressed inside a loop 1 Answer

Trying to add a delay to an Instantiate in a For Loop 0 Answers

Script makes Uniy Freeze 0 Answers

I got Error for Looping, it can't Stop.. how to fix it? 1 Answer

Trying to add a tracker to enemy AI either prefab or with reference 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