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 zak666 · Jul 09, 2017 at 06:07 AM · spawning-enemies

Spawning Enemy spawns more then MaximumEnemy?

o, SO i set up this simple enemy spawner and when you kill one it spawns another awesome, however I end up with 20 Medium enemies rather then a maximum of 5..... any Idea's on why its going over the limit?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SpawnEnemy : Photon.MonoBehaviour {
 
 
     public float maximumEnemy = 20;
     public float maximumEnemyMedium = 5;
     private GameObject SpawnLocation;
 
     public GameObject[] Enemies;
     public int index;
 
     public GameObject[] Enemies2;
     public int index2;
 
     // Use this for initialization
     void Start () {
         SpawnLocation = this.gameObject;
     }
     
     // Update is called once per frame
     void Update () {
         if (PhotonNetwork.isMasterClient == true) {
 
             Enemies = GameObject.FindGameObjectsWithTag ("EnemySmall");
             index = Enemies.Length;
 
             Enemies2 = GameObject.FindGameObjectsWithTag ("EnemyMedium");
             index2 = Enemies2.Length;
 
             if (index > maximumEnemy) 
                 return;
             
                 GameObject Clone = PhotonNetwork.Instantiate ("Enemy", SpawnLocation.transform.position, SpawnLocation.transform.rotation, 0);
 
             if (index2 > maximumEnemyMedium)
                 return;
                 GameObject Clone2 = PhotonNetwork.Instantiate ("EnemyMedium", SpawnLocation.transform.position, SpawnLocation.transform.rotation, 0);
             
             
         }
     }
 
 
     //-----------------------------------------------------------------------------------------------------------
 
 
 }
Comment
Add comment · Show 2
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 Jwizard93 · Jul 10, 2017 at 01:53 AM 0
Share

Hmm, sure you got the prefabs right as SpringWtaer suggests? Also sure those prefabs have the right tags. Once all that checks out change your approach. You Don't want to be looking for Gameobjects every frame that is wildly inefficient. Store the active list of enemies so you don't have to keep finding them.

avatar image Cornelis-de-Jager · Jul 10, 2017 at 02:03 AM 0
Share

As the other has been suggesting, double check you have the correct enemy assigned. Ensure that the Tags are correct for all.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by springwater · Jul 09, 2017 at 06:41 AM

if (index > maximumEnemy) return; else// <------ would add "else" here I think and all such parts of the script. GameObject Clone = PhotonNetwork.Instantiate ("Enemy", SpawnLocation.transform.position, SpawnLocation.transform.rotation, 0);

not sure if that will help keep it clean.. but you might also check to make sure your medium enemy prefabs are actually the one you wanted to drag into the correct slots in the inspector..you could try steppng through the code with monos attachment feature.

Comment
Add comment · 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

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

70 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

Related Questions

radom spawn points 1 Answer

Need some help with Enemy Spawning Script... 1 Answer

Enemy Wave System Error -1 Answers

How to Spawn an enemy behind player? 1 Answer

Problem with WaitForSeconds() in a nested loop 2 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