Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Nov 10, 2020 at 04:26 AM by raziel183 for the following reason:

Found the answer elsewhere

avatar image
0
Question by raziel183 · Nov 10, 2020 at 01:35 PM · instantiatefreezeplayinfinite

Create with Code 4.4 For-Loops For Waves: play mode freeze

Hi I am a beginner and started a little while ago using my laptop to learn how to use Unity but today I ran into a problem with this tutorial.

In Create with Code 4.4 For-Loops For Waves After completing video 2, his play mode worked, while mine freezes and my memory use jumps up to about 95%. I suspect my laptop doesn't enough enough grunt to process the loop and instantiate the game objects in random positions.

I will paste the code below (I continued on despite being unable to test) and attach a pic of my specs.

This is the code (please not I changed some variable names to be more intuitive to me:

public class Spawner : MonoBehaviour { public GameObject prefabSlot; public GameObject pUpPrefab;

 private float spawnRange = 8.0f;
 public int enemyCount;
 public int waveNumber = 1;

 void Start()
 {
     SpawnWave(waveNumber);
     Instantiate(pUpPrefab, GenerateSpawnPos(), Quaternion.identity);
 }

 void Update()
 {
     enemyCount = FindObjectsOfType<Enemy>().Length;

     if (enemyCount == 0)
     {
         waveNumber++;
         SpawnWave(waveNumber);
         Instantiate(pUpPrefab, GenerateSpawnPos(), Quaternion.identity);
     }
 }

 void SpawnWave(int enemyPopulation)
 {
  
     for (int i = 0; i < enemyPopulation; i = i++)
     {
     Instantiate(prefabSlot, GenerateSpawnPos(), prefabSlot.transform.rotation);
     }
 }

 private Vector3 GenerateSpawnPos()
 {
     float spawnPosX = Random.Range(-spawnRange, spawnRange);
     float spawnPosZ = Random.Range(-spawnRange, spawnRange);
     float dropHeight = 0.0f;

     Vector3 randomPos = new Vector3(spawnPosX, 0, spawnPosZ);

     return randomPos;
 }

}

alt text

2.png (18.0 kB)
Comment
Add comment · Show 1
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 raziel183 · Nov 10, 2020 at 04:25 AM 0
Share

NV$$anonymous$$. A friend just got back to me with the answer:

I had: for (int i = 0; i < enemyPopulation; i = i++)

but I needed either:

for (int i = 0; i < enemyPopulation; i++)

or

for (int i = 0; i < enemyPopulation; i = i+1)

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

170 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 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

Editor freezes after play 3 Answers

Play button takes forever to load, how to fix? 1 Answer

Unity crashing when I hit the Play button. 0 Answers

Checking if object intersects? 1 Answer

Scrolling level Instantiate after cycle 0 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