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 FatalNightmare · Jan 05, 2013 at 11:19 PM · enemytimerspawner

Help with Enemy Spawner!

Hi, so I am trying to make code for a Spawner that spawns my enemy prefab after 300 seconds and spawns 15 enemies. Then after 900 seconds it spawns 15 more enemies.Javascript would be preferred. Any help would be great thanks!

 public var enemy : GameObject;
 public var WaitTime : int;
 
 function Start () {
 
     yield WaitForSeconds(WaitTime);
     InvokeRepeating("SpawnEnemy", 3, 3);
 }
 
 function SpawnEnemy() 
 {
 
     //Instantiate the enemy prefab
    
     var enemyClone : GameObject = Instantiate(enemy, Vector3.zero, Quaternion.identity);
     
    
 }
 

This is the code I am using for the Spawner, it spawns the enemy at 0,0,0 how Do I make the enemy spawn on the object that I place this code on.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Piflik · Jan 06, 2013 at 12:14 AM

Instead of Vector3.zero use transform.position...

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 FatalNightmare · Jan 06, 2013 at 12:25 AM 0
Share

Hey thanks that worked but now it spawns 8 enemies every 3 seconds how do I get it to spawn 1 enemy every 3 seconds

avatar image Piflik · Jan 06, 2013 at 04:25 AM 0
Share

I can not see anything in the code you provided that would cause 8 enemies to spawn simultaneously. Are you sure you don't have 8 of these spawners sitting on top of each other or one spawner with 8 instances of this script?

avatar image
0

Answer by bzerk122 · Jan 06, 2013 at 03:47 AM

I personally think you should do something like this:

 public var enemy : GameObject;
 public var WaitTime : float;
 //new timer
 private var timer : float;
 
 
 function Update(){
 
 if(timer < WaitTime){
 timer+=Time.DeltaTime;
 
 }
 if(timer>=WaitTime)
 {
 timer = 0;
    //Instantiate the enemy prefab
 
     var enemyClone : GameObject = Instantiate(enemy, transform.position, Quaternion.identity);
 
    }
 }

I don't know if this work i usually write in c# but that should work(Its count to wait time then instantiates then resets)

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
avatar image
0

Answer by jeffbori · Oct 13, 2016 at 04:35 PM

i think to use yield WaitForSeconds(WaitTime); you need to start a coroutine first?

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

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

Access a instantiated gameobject from a enemy spawner 4 Answers

Spawn game objects on a timer 2 Answers

Adding a timer to spawner 2 Answers

Spanwer Script only spawns when Player is close and more. 1 Answer

Adding a counter? 1 Answer


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