Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 heCAT · Jul 27, 2015 at 11:02 AM · whilewhile-loopincreaseiteratewhile loop

Iterator variable not increasing.

I've been trying to create a basic random asteroid field out of spheres and it was going so well until I realized that it never stopped generating. I used a while loop and made a variable representing the iterator (i) and did some code inside of it. I ended the while loop with an i++; but when i tested it, it didn't seem as if the iterator increased. My code: using UnityEngine; using System.Collections; public class AsteroidGeneration : MonoBehaviour { %|-1008245593_1|% public int objectCount; %|10977004_2|% %|1407053197_4|% %|61866010_5|% %|-1777223416_6|% %|1768835771_7|% Vector3 ranV = new Vector3 (Random.Range(0,spread), Random.Range(0,spread), Random.Range(0,spread)); %|-1190291132_9|% %|-709725649_10|% %|-1464503037_11|% %|-1745120846_4|% %|468739861_13|% }

I cant seem to solve this problem. Any help is appreciated!

If there is a problem with you seeing the code, here's a picture: alt text

iteratorprobelm.png (11.1 kB)
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
1
Best Answer

Answer by PAHeartBeat · Jul 27, 2015 at 11:17 AM

Hi @heCAT,

Why you set i to zero every frame? are trying to make your own particle system ? If not then declare i out side update and then only once set i = 0 in Start or Awake Method.

In this case you get only see value in debug is value which set in public varialbe public int objectCount

if you want to create astroid field once only then replace while loop with if statement and declare I out side of Update function. so it will genrate each astroid one bye one each frame, and once rich to astroid count via objectCount it will stop genrateing new astroids around the sphere.

Comment
Add comment · Show 1 · 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 heCAT · Jul 27, 2015 at 04:51 PM 0
Share

Oh, wow thanks! I cant believe I didn't notice that before! It helped a lot, and i'll try to remember that!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

wierd infinite while loop 1 Answer

while loop does not pick up again on continue 0 Answers

Vector3.MoveTowards becomes instant in while loop or freezes unity 1 Answer

Using a while loops to repeatedly execute a method? 2 Answers

Quaternion.Slerp issue 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