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 user-10729 (yahoo) · Mar 25, 2011 at 06:01 PM · enemytimespawn

random enemy spawn from day night cycle

hello im lookin for some tips on spawning enemies by time of day my goal is to.. the enemies spawn random locations say 1000 enemies spawn per hour when the hour is up checks remaining enemies and re populations random locations across the map up to 1000 in total ( in the hour 100 died so it respawns 100 to keep the 1000 quota ) and also have it so at night it increases the spawn amount to say 2000 per hour then when its morning again back to 1000 per hour.. iv read abunch of answers to questions about enemies and day night cycle and i havnt tried to put what iv learned to test yet... i thought id ask maybe get a general outline of how to go about my specific question instead of trying to do some mix match things iv picked up along the way.. thanks for the help hope to hear some thoughts soon

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Justin Warner · Mar 25, 2011 at 07:36 PM

Just keep a tally of how many enemies their are, and in the awake function check to see if it's above 1000, if it is, then "destroy" all the extras, and if it's less than 1000, make a new var, and have it loop instantiate those... You can try it in the update function, but I'm thinking more of the second you start the scene, it should populate.

Um, and then just have a time function that gets the time, and check it... Could get this from the internet (WWW stuff)< or it could be something you make yourself: http://www.google.com/search?client=opera&rls=en&q=time+in+unity3d&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest

But maybe this'll help a little?

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 Niklas · Mar 25, 2011 at 08:13 PM

I Wrote a bunch of code. Hope this is helpfull.

This registers each spawnPoint to a SpawnMaster. This spawn master ticks time and triggers Repopulate on a random sub-list of ISpawnPoint's at each time interval.

The spawn point could instatiate objects after a set of rules that you define, but for now i only make it really basic. (Not really a working example, but mostly to giva a hint of what you could do) :)

For now this only divides the number of creatures even among selected spawn points and repopulates them. This behaviour could be change by changing the selection behaviour to take into account the number of creatures currently on each spawn point, but i will leave that algorithm to you since i dont really know how this spawning should happen.

Hopefully this examples can help you on your way. :)

Regards,

( The code is totally untested so there might be errors )

SpawnMaster interface

public interface ISpawnMaster
{
    void AddSpawnPoint(ISpawnPoint point);
}

SpawnMaster

public class SpawnMaster : MonoBehaviour, ISpawnMaster { public int NumRandomSpawnPoints = 5; public int Quota = 1000; public float SpawnInterval = 5; private float spawnTimer = 0.0f;

 private List&lt;ISpawnPoint&gt; _spawnPoints;
 void Awake()
 {
     gameObject.tag = "SpawnMaster";
 }

 void Start()
 {
     _spawnPoints = new List&lt;ISpawnPoint&gt;();
 }

 void Update()
 {
     spawnTimer += Time.deltaTime;
     if (spawnTimer &gt; SpawnInterval)
     {
         spawnTimer -= SpawnInterval;

         FillQuota();
     }
 }

 public void AddSpawnPoint(ISpawnPoint point)
 {
     _spawnPoints.Add(point);
 }

 void FillQuota()
 {
     if (Quota &gt; 0)
     {
         if (_spawnPoints.Count &gt; NumRandomSpawnPoints)
         {
             List&lt;ISpawnPoint&gt; selectedPoints = new
             List&lt;ISpawnPoint&gt;();
             while (selectedPoints.Count !=
             NumRandomSpawnPoints)
             {
                 foreach (ISpawnPoint point in _spawnPoints)
                 {
                     if (!selectedPoints.Contains(point))
                     {
                         if (Random.Range(0, 1) &gt; 0)
                         {
                             selectedPoints.Add(point);
                         }
                     }
                 }
             }

             foreach (ISpawnPoint point in selectedPoints)
             {
                 SpawnList(selectedPoints);
             }
         }
         else
         {
             SpawnList(_spawnPoints);
         }
     }
 }

 void SpawnList(List&lt;ISpawnPoint&gt; list)
 {
     foreach (ISpawnPoint point in list)
     {
         point.Repopulate(list.Count / Quota);
     }
 }

}

SpawnPoint interface

public interface ISpawnPoint
{
    void Repopulate(int num);
    int NumCreatures();
}

Creature

class Creature : MonoBehaviour
{
    public string CreatureName = "Dangerous evil monster";
    public bool Enabled = true;
}

Creature spawner (SpawnPoint)

public class CreatureSpawner : MonoBehaviour, ISpawnPoint { private List<Creature> _creatures;

// Use this for initialization void Start () { _creatures = new List<Creature>(); // Not sure you can find interface using this method, but if //you cant, you'll probably figure it out (GameObject.FindObjectOfType(typeof(ISpawnMaster)) as ISpawnMaster).AddSpawnPoint(this); }

 void Update()
 {
     // You wont need to do this each update. A better way could
     // be a callback when creature dies
     foreach (Creature creature in _creatures)
     {
         if (!creature.Alive)
         {
             // kill and remove
         }
     }
 }

 public int NumCreatures()
 {
     return _creatures.Count;
 }

 public void Repopulate(int num)
 {
     for (int i = 0; i &lt; num; ++i)
     {
         _creatures.Add(new Creature());
     }
 }

}

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

No one has followed this question yet.

Related Questions

c# Enemy's spawning over time, problem 2 Answers

More Efficient Enemy Spawning Than This? 2 Answers

How to make an enemy attack every few seconds 1 Answer

Trying out a unique method of spawning enemies. Someone want to help sort out the logic of it? 1 Answer

How can I spawn an enemy "behind the nearest corner"? 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