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 JoshMBeyer · Dec 17, 2012 at 11:41 AM · c#enemyspawnzombieenemies

How to spawn enemy? (Enemies)

Hi, I've been trying to write a script for my (ZombieStyle) FPS so when the game first loads, several "enemies" will be spawned at random spawn points I have set throughout my map. (I used empty GameObjects) I want a lot of zombies walking around aimless (Have already written the AI all works fine) I just want it to be completely random so while playing I don't learn where I will find them. I want it random.

Also if I start killing zombies to quickly then there wont be any left and thats boring. So how would I make it to where if there are less that however many zombies, Instantiate however many(Random.Range maybe). Just something to keep a decent amount of zombies on the street. Sorry to ask for a script, but I've been searching for the past 4 hours and trying with the API and can't seem to make anything work.

Here is what I have so far, I have no clue what I am doing so I started it off as spawning just 1 prefab. I can't figure out how to make Instantiate work, it says it requires 4 arguements or something. If you can write it to spawn alot when the game starts that would help.

PS: My game is all in C#

 using UnityEngine;
 using System.Collections;
 
 /// <summary>
 /// This is the EnemySpawn script.
 /// This script is attached to the SpawnManager(EmptyGameObject).
 /// </summary>
 
 public class EnemySpawn : MonoBehaviour {
 
     //--------------Variables Start-----------------
 
     private   GameObject[]    enemySpawnPoints;
     private   int             enemySpawnGroup       = 0;
     public    Transform        enemyAI;
     public    bool             iAmAnEnemy         = false;
 
     //--------------Variables End------------------
 
 
     void Awake()
     {
        //Call the SpawnEnemy function.
        SpawnEnemy();
     }
 
     // Use this for initialization.
     void Start () {
     }
 
     // Update is called once per frame.
     void Update () {
     }
 
     void SpawnEnemy ()
     {
        //Find all of the enemy spawn points and place a reference to them in the array
        //enemySpawnPoints.
        enemySpawnPoints = GameObject.FindGameObjectsWithTag("SpawnEnemy");
 
        //Randomly select one of those spawn points.
        GameObject randomEnemySpawn = enemySpawnPoints[Random.Range(0, enemySpawnPoints.Length)];
 
        //Instantiate the enemy at the randomly selected spawn point.
        Instantiate(enemyAI, randomEnemySpawn.transform.position,
                            randomEnemySpawn.transform.rotation, enemySpawnGroup);
     }
 }
Comment
Add comment · Show 2
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 JoshMBeyer · Dec 17, 2012 at 10:45 AM 0
Share

Sorry about the variables, For some reason after i hit "Ask question" they went all out of order.

avatar image Fattie · Dec 17, 2012 at 11:55 AM 0
Share

it's possible this very long post could help you

http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html

1 Reply

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

Answer by Maulik2208 · Dec 17, 2012 at 01:39 PM

Why don't you try a timer let say timer of 1 min and after every 1 min start instantiating the Zombies..... Not sure but this could be a way you can have a good amount of enemy to kill..........for timer you can use Enumarator and wait for second and you are all set to go......Cheers Enjoy.......Don't forget to tick if found useful

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Enemies spawn on top of each other(C#)(Unity) 1 Answer

Wave Spawner not working |Does not detect if an object is destroyed 1 Answer

Extend only a part of an object unity 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