Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Cheenodash · Feb 16, 2013 at 05:46 PM · javascriptprefab

Prefabs double at each instance?

Hey, I'm making a 2d game, which requires 6 prefabs which spawn enemies at specific intervals. But when there are some instances already in the game, when the prefab instantiates again, it makes 2 of the prefabs spawn, and on the third time 3 will spawn and so on. I have all of the prefabs above the screen, out of view. Here is the code on my prefabs: var Enemy:Transform; private var Timer:float;

     function Awake() {
     Timer = Time.time + 5;
     }
      
     function Update() {  
     if (Timer < Time.time) { 
     Instantiate(Enemy, new Vector3(-2.567029, -1.864899, -4.613899), transform.rotation); 
     Timer = Time.time + 5; 
     }

This is the code that spawns the enemies at certain times. Is there a way to stop the doubling up when they spawn? It means my points system is screwed up! Cheers

Comment
Add comment · Show 3
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 flaviusxvii · Feb 16, 2013 at 06:00 PM 0
Share

This script will make an Enemy at the exact same spot every 5 seconds. That's not what you want?

avatar image Cheenodash · Feb 16, 2013 at 06:04 PM 0
Share

Yeah I do, it spawns the first enemy fine, but when another 5 seconds pass, two spawn ins$$anonymous$$d of one.

avatar image flaviusxvii · Feb 16, 2013 at 06:09 PM 0
Share

You don't have this script attached to the enemy do you? Each object with this script attached will make a new enemy every 5 seconds.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by flaviusxvii · Feb 16, 2013 at 06:10 PM

Don't put this script on your "Enemy" prefabs. Attach this to an empty game object somewhere in the scene, then it'll spawn one enemy every 5 seconds.

Comment
Add comment · Show 5 · 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 Cheenodash · Feb 16, 2013 at 06:12 PM 0
Share

Cheers, I'll try that in a $$anonymous$$ute :D

avatar image Cheenodash · Feb 16, 2013 at 06:12 PM 0
Share

Just ready what you posted above, makes sense now!

avatar image flaviusxvii · Feb 16, 2013 at 06:24 PM 0
Share

Remember to upvote/accept answers! And re$$anonymous$$d others to do so!

avatar image Cheenodash · Feb 16, 2013 at 06:42 PM 0
Share

Just tested it, works perfectly, thank you. $$anonymous$$arked as answer

avatar image Stalkers · Apr 25, 2016 at 11:32 AM 0
Share

Hey flaviusxvii, I had the same problem and your solution fixed it, thanks heaps! :D. I was hoping you can explain why that happens?

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

11 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

Related Questions

Set a Prefab's variable when you instantiate it, but before it calls Awake? 2 Answers

Instantiate a Prefab thats been passed through 2 scripts? 2 Answers

Unity Frame Drop From Instantiating Prefab that has script 0 Answers

Instantiate a prefab with a key press to a relative location? 1 Answer

Change Variable on Another 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