- Home /
              This post has been wikified, any user with enough reputation can edit it. 
            
 
             
               Question by 
               Ruds · Jan 23, 2015 at 07:11 AM · 
                fpsenemyinvokeinvokerepeating  
              
 
              InvokeRepeating is not stoping.
I am trying to make enemy spawn using InvokeRepeating but any how i am not able to stop it when i have enough number of enemy Here is the code can any one tell me what went wrong.
     public GameObject enemy;                // The enemy prefab to be spawned.
     public float spawnTime = 7.0f;            // How long between each spawn.
     public Transform[] spawnPoints;         // An array of the spawn points this enemy can spawn from.
     public int LevelMaxEnemy=10;
     public int numofEnemy=0;
     void Start ()
     {
         // Call the Spawn function after a delay of the spawnTime and then continue to call after the same amount of time.
         InvokeRepeating ("Spawn", spawnTime, spawnTime);
 
     }
     
 
     void Spawn ()
     { 
         // If the player has no health left...
         if(PlayerMovementScript.playerHealth <= 0f)
         {
             // ... exit the function.
 
             return;
         }
         if(numofEnemy > LevelMaxEnemy){
             // ... exit the function.
             
             return;
         }
 
         else{
             // Find a random index between zero and one less than the number of spawn points.
             int spawnPointIndex = Random.Range (0, spawnPoints.Length);
             
             // Create an instance of the enemy prefab at the randomly selected spawn point's position and rotation.
             Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
             numofEnemy = numofEnemy + 1;
             
         }
 
     }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Ruds · Jan 23, 2015 at 09:24 AM
Thnaks for your support but it fix with InvokeRepeating ("Spawn", spawnTime, 0.0 f); it was just resting all the values of the local variables after that time interval
Your answer
 
 
             Follow this Question
Related Questions
Invoke() and InvokeRepeating() not working on webplayer? 1 Answer
Repeating after variable delay 1 Answer
CancelInvoke cant cancell,Updating InvokeRepeating 1 Answer
Enemy fire rate? help! 2 Answers
Complete AI Tutorial? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                