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 /
This question was closed Sep 28, 2019 at 03:18 PM by tormentoarmagedoom for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by PruneDealer · Sep 28, 2019 at 03:08 PM · spawningspawning problems

How do I stop enemy from spawning on start?

I am making an enemy spawn script here and it works extremely well except for one little detail. As soon as you hit play, there are already two enemies coming at you (One for each of my two spawners) How do I prevent this from happening, I've tried to work it out with no luck and I'm fairly new here. Thanks :)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SpawnScript : MonoBehaviour
 {
 
     public GameObject enemy1, enemy2;
 
     public int nextSpawn = 0;
     
 
     int whatToSpawn;
 
     void Update()
     {
         Debug.Log(nextSpawn);
 
       if (nextSpawn == 0)
         {
             whatToSpawn = Random.Range(1, 3);
             Debug.Log(whatToSpawn);
 
             switch (whatToSpawn)
             {
                 case 1:
                     Instantiate(enemy1, transform.position, Quaternion.identity);
                     break;
                 case 2:
                     Instantiate(enemy2, transform.position, Quaternion.identity);
                     break;
             }
             nextSpawn = Random.Range(60, 100);
         }
         else if(nextSpawn > 0)
         {
             nextSpawn--;
         }
     }
 }
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

  • Sort: 
avatar image
0
Best Answer

Answer by tormentoarmagedoom · Sep 28, 2019 at 03:18 PM

Hello there!

You should leran about time usage in unity.

You are using Update as a "timer" using frames to count to know when to spawn again...

Really, I strongly recommend 300% to STOP, and spend next 5-10 hours learning about this things (look for them, watch tutorials in youtube, etc...) If you pretend to build a house, firt at least learn to how to make concrete... If not when reaching the roof will see your house is not stable and will fall down.

As I said, stop, and spend next 5-10 hours reading and watching tutorials about all this things (dont be afaraid to dont understand.... for sure at the begining will understand NOTHING, but hour by hour will see you understand a litle bit more, so rewatch that tutorial you didnd understand at the begining :D

Look for this at youtube/google using the word UNITY first:

  • Time

  • Time.deltaTime

  • IEnumerator

  • Corutines

  • Countdown

  • Frames

  • Update / FixedUpdate / LateUpdate

  • Usage of methods

Good luck!

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

Follow this Question

Answers Answers and Comments

182 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 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

Spawn system that doesn't instantiated enemies on top of player or each other (C#) 2 Answers

How do I stop multiple spawns? 0 Answers

Problem with the enemy spawn,Problem with enemy 0 Answers

Random.Onunitsphere confusing different spheres 1 Answer

Spawn a box and when i press space drop that box 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