• 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 /
  • Help Room /
avatar image
0
Question by droni · Oct 10, 2015 at 06:42 PM · loops

while stops script after looping 1 time

Hi guys, it seems that my script get stopped, when the while loop dont loop and instead just runs one time. Here's my code:

 int count = 0;
 int repetitions = Random.Range(1,4);
 while(!(count == repetitions)) 
     {
         yield return new WaitForSeconds (0.5f);
         count += 1 ;
     }

If the repetitions int gets 1 the script breaks after the loop, unity still works! Please help me need your support :D THX

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 meat5000 ♦ · Oct 15, 2015 at 07:14 PM 0
Share

Is it a coroutine?

avatar image droni meat5000 ♦ · Oct 22, 2015 at 07:44 PM 0
Share

yes its a coroutine

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Oct 10, 2015 at 09:12 PM

just use a for loop instead

Comment
Add comment · Show 6 · 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 droni · Oct 15, 2015 at 07:09 PM 0
Share

what did you mean should i use for ?

avatar image meat5000 ♦ droni · Oct 15, 2015 at 07:15 PM 0
Share

A 'for' loop. Check it out in the Learn section of the site.

avatar image droni meat5000 ♦ · Oct 16, 2015 at 05:33 PM 0
Share

that's also didnt helped i know how to handle loops :P but it's don't working, if the loop just runs one time!

Show more comments
avatar image droni · Oct 16, 2015 at 11:07 PM 0
Share

thats didnt worked what did you mean, with it must be in order Update; it works fine i just cant reach another scripts, my fault i change the level with telling an another script the name and then changing a bool to true

avatar image meat5000 ♦ droni · Oct 16, 2015 at 11:44 PM 0
Share

Sorry, my terrible english. Ill edit

avatar image
0

Answer by droni · Oct 17, 2015 at 01:31 AM

Update:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class FillBar : MonoBehaviour
 {
     public Image FillBarImage;
 
     private int foundResults = 0;
     private int count = 0;
     private float fillamount = 0.0f;
 
     void OnEnable()
     {
         FillBarImage.fillAmount = 0;
         fillamount = 0;
         count = 0;
         foundResults = Random.Range(1, 4);
         float floattrans = foundResults;
         float fillPart = 1 / floattrans;
         StartCoroutine(WaterF(fillPart));
     }
     IEnumerator WaterF(float partValue)
     {
         while (!(count == foundResults))
         {
             count += 1;
             fillamount += partValue;
             yield return new WaitForSeconds(0.5f);
         }
         CTRL.i_water += 1; //i_water = inventory Water
         CTRL.ChangeLevelName = "menu"; // transform to enable
         CTRL.ChangeLevel = true;  // start process changing (transforms(based on ui))
     }

i tried to cut the useless things out thats my script its only accesing intern variables its also cant just runs a random function

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

32 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

Related Questions

From a scale from 1 to 10 how bad are loops inside loops 1 Answer

Instantiating game objects in spiral pattern 0 Answers

For loop not working 1 Answer

trying to instantiate an object a random number of times ,how do i spawn something in a random ammount of times? 0 Answers

if loop running when it shouldn't 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