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 Creative Inventory · Oct 06, 2015 at 05:38 PM · bugspawnproblemawave

Spawning Bug.

Okay I have a game which involves spawning. My spawn points are both left and right. I have this wave that spawns once "delay" is completed. I am spawning moving object that does get destroyed. (which I am trying to do) At first it seems nice, no problems but after a few minutes (2 mins) it suddenly starts spawn 1000 upon 1000's of my moving objects. How would I stop this!!! I think it may be because I haven't got a destroy script, to destroy the moving objects, but I'm no genius! Please if anyone can help it would be much appreciated. Thank you!!! Here's my script:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;

  [System.Serializable]
  public class WaveAction
  {
  public string name;
  public float delay;
  public Transform prefab;
  public int spawnCount;
  public string message;
    }

  [System.Serializable]
  public class Wave
  {
  public string name;
  public List<WaveAction> actions;
   }



  public class WaveGenerator : MonoBehaviour
  {
   public float difficultyFactor = 0.9f;
   public List<Wave> waves;
   private Wave m_CurrentWave;
   public Wave CurrentWave { get {return m_CurrentWave;} }
   private float m_DelayFactor = 1.0f;
   public GameObject ObjectToSpawn; 
 
   IEnumerator SpawnLoop()
   {
      m_DelayFactor = 1.0f;
      while(true)
      {
          foreach(Wave W in waves)
          {
             m_CurrentWave = W;
             foreach(WaveAction A in W.actions)
             {
                 if(A.delay > 0)
                     yield return new WaitForSeconds(A.delay * m_DelayFactor);
                 if (A.message != "")
                 {
                     // TODO: print ingame message
                 }
                 if (A.prefab != null && A.spawnCount > 0)
                 {
                     for(int i = 0; i < A.spawnCount; i++)
                     {
                         
                         // Random position within this transform
                         Vector3 rndPosWithin;
                         rndPosWithin = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f));
                         rndPosWithin = transform.TransformPoint(rndPosWithin * .5f);
                         Instantiate(ObjectToSpawn, rndPosWithin, transform.rotation);  
                         
                     }
                 }
             }
             yield return null;  // prevents crash if all delays are 0
         }
         m_DelayFactor *= difficultyFactor;
         yield return null;  // prevents crash if all delays are 0
     }
 }
 void Start()
 {
     StartCoroutine(SpawnLoop());
 }
 

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Inok · Oct 06, 2015 at 07:37 PM

Ok looks like i know what is wrong: look at this line "m_DelayFactor *= difficultyFactor;" you multiply initial delay (1.0f) with difficculty factor (0.9), each "round" your delay becomes lower and lower with more speed because you multiply by less then 1. So problem in calculation of delay lowering.

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 Creative Inventory · Oct 07, 2015 at 06:36 PM 0
Share

So what should I change it to?

avatar image Creative Inventory · Oct 08, 2015 at 06:23 PM 0
Share

@Inok could you please notify me as soon as possible

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

31 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

Related Questions

Can sb help? Artifact with terrain or another objects 0 Answers

Problem of basic shader in unity help pls 0 Answers

How to add a wave in my spawn script 1 Answer

Spawning bug problem 1 Answer

Wave spawner script 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