Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Aug 26, 2021 at 10:10 PM by Nosmo for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Nosmo · Aug 25, 2021 at 11:59 PM · spawnspawningtriggersmultiplespawning problems

How do I stop multiple spawns?

I'm spawning alien ships as a vehicle goes through a trigger zone, but it spawns 11 versions of it.

I narrowed it down to the colliders on the vehicle but getting rid of them isn't an option.

Any suggestions how could I fix this issue?

Comment
Add comment · Show 8
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 rage_co · Aug 26, 2021 at 05:13 AM 0
Share

can you share your code for this?

avatar image Nosmo rage_co · Aug 26, 2021 at 09:28 AM 0
Share

I'm trying to make a train spawn a drone as it goes through a trigger.

Here is the code:


 public class Spawn_Drone : MonoBehaviour
 {
 public Transform Drone;
 public Transform SpawnPoint;
 public Transform TeleportEffect;

 void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.tag == "DroneActivator")
     {
         Spawn();
         Debug.Log("Active 1: Spawn Drone script");
     }
 }

 void Spawn()
 {
     Instantiate(Drone, SpawnPoint.position, SpawnPoint.rotation);
     Instantiate(TeleportEffect, SpawnPoint.position, SpawnPoint.rotation); //addition
     Debug.Log("Drone Active: Spawn Drone script");
 }

}


it works when its an asset with 1 collider but when I add another collider to it that's when it makes multiples

avatar image rage_co Nosmo · Aug 26, 2021 at 12:26 PM 0
Share

There's the solution with lists that comes to $$anonymous$$d and it should work as long as the colliders are on the same game object (if not, you can tell me later and with a slight modification it can work with that too)

 public class Spawn_Drone : MonoBehaviour
  {
  public Transform Drone;
  public Transform SpawnPoint;
  public Transform TeleportEffect;
  public List<GameObject> activators = new List<GameObject>();
 
  void OnTriggerEnter(Collider col)
  {
      if (col.gameObject.tag == "DroneActivator")
      {
        if(!activators.Contains(col.gameObject))
        {
          activators.Add(col.gameObject);
          Spawn();
          Debug.Log("Active 1: Spawn Drone script");
        }
      }
  }
 
 void OnTriggerExit(Collider col)
  {
      if (col.gameObject.tag == "DroneActivator")
      {
        if(activators.Contains(col.gameObject))
        {
          activators.Remove(col.gameObject);
          Debug.Log("collision ended, object removed from list");
        }
        else
        {
           Debug.Log("collision ended, but object was not in list");
         }
      }
  }
 
  void Spawn()
  {
      Instantiate(Drone, SpawnPoint.position, SpawnPoint.rotation);
      Instantiate(TeleportEffect, SpawnPoint.position, SpawnPoint.rotation); //addition
      Debug.Log("Drone Active: Spawn Drone script");
  }
 }

Even a bool could have worked here but i made it with a list so that you can even have multiple activator objects in case you ever need them....hope this helps!

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

172 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

Related Questions

Spawn a box and when i press space drop that box 0 Answers

problem when i spawn to many Enemy the game be slower 1 Answer

Networking concept and spawning questions 1 Answer

Check if there's no GameObject with specific tag in the field (in the camera view) 0 Answers

[C#] Only one instantiate object is working, the rest is not.. Help meee 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