• 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 julinzp · Jan 22, 2019 at 11:02 AM · spawnspawningspawning problemsspawnerspawning-enemies

How to spawn all humans at once and activate then with time?

What I am trying to do is to spawn humans that will simply pass by my charactarter, I have wrote a script However constant spawning causes some flickering in Oculus, thus I want to redo it the way that all humans will be spawned at once and activated with time, but I am worried that humans will overlap each other and it will cause problems. Will be thankful if you could recommend me an elegant way to solve this problem.

         void Spawn()
         {
                 Debug.Log("Spawn Function Activated");
                 RandomHuman = Random.Range(0, humans.Length);
                 GameObject spawnedPrefab = Instantiate(humans[RandomHuman], new Vector3(transform.position.x, 0, transform.position.z), transform.rotation);
              }
     
         void Start()
         {
             InvokeRepeating("Spawn", 0f, 3f);
         }
     
     
         void Update()
         {
             SpawnWait = Random.Range(SpawnLeastWait, SpawnMostWait);
     
         }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · Jan 22, 2019 at 11:09 AM

They are just static objects that dont move? the best way of doing this is spawning a pool of objects at the start in awake or something like that and change the spawn method to rpositionate, and rather than instantiate the object just positionate one of the objects of the pool in the desired 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 julinzp · Jan 22, 2019 at 11:18 AM 0
Share

No, that 's the problem, they are not static and have and animation script attached .

avatar image xxmariofer julinzp · Jan 22, 2019 at 11:21 AM 0
Share

Then just spawn them at the start and use the GameObject.SetActive() method, just repositionate and reactivate them, i would suggest checking a tutorial of object pooling if its your first time doing this.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

102 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

Related Questions

How to spawn enemies at different locations and avoid overlapping each other 2 Answers

How to increase the spawn rate of an object over time? 2 Answers

SPAWNING ENEMIES and controlling the amount/interval 1 Answer

Spawning help 1 Answer

How to Make an Expanding Spawn Area for Prefabs? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges