Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by OctoMan · Nov 03, 2015 at 07:37 PM · ienumeratorbreak

Leave/End the IEnumerator the right way.

Hi there,

i have an IEnumerator which has to do a ColorCheck.

 IEnumerator StartColorCheck()
 {
     if(checkingColors)
     {
         //Debug.Log ("can't StartColorCkeck");
         yield break;
     }
     checkingColors = true;

     yield return new WaitForSeconds (0.5f);

     for (int i = 0; i < allcards.Length; i++)
     {
         CC = allcards[i].GetComponent<ColorCheck>();
         CC.CheckColors();

         CardMatches += CC.matches;
     }
     checkingColors = false;
 }

The Problem is, it seems to stack up, until all calls are gone through it. I call it from a

  void OnMouseUp()

but when i click to fast for example, all clicks seem to stack until all ran through it. Is there a way to avoid that? Because CardMatches returns a wrong value while it's repeating all over and over.

Thanks in advance.

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 Statement · Nov 03, 2015 at 08:23 PM

I don't really understand your problem. Doesn't the above example work?

Note you could also replace that with a normal function and use Invoke.

 void OnMouse()
 {
      SingleInvoke("ColorCheck", 0.5f); // Call ColorCheck after half a second.
 }
 
 void SingleInvoke(string method, float time)
 {
     CancelInvoke(method); // If method is pending, cancel it.
     Invoke(method, time);
 }
 
 void ColorCheck()
 {
      for (int i = 0; i < allcards.Length; i++)
      {
          CC = allcards[i].GetComponent<ColorCheck>();
          CC.CheckColors();
          CardMatches += CC.matches;
      }
 }

CancelInvoke, Invoke

Comment
Add comment · Show 3 · 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 OctoMan · Nov 03, 2015 at 08:32 PM 0
Share

Basicly all works yes, but if i click to fast it mess up the result of Card$$anonymous$$atches since CheckColors seem to count to many.

$$anonymous$$aybe it's be cause my On$$anonymous$$ouse()

 void On$$anonymous$$ouseUp()
     {
         if (isdragged && hitPlayfield) 
         {
             transform.position = newPosition;
             isdragged = false;
             //play sound
             CardAudio.clip = SwapClip;
             CardAudio.Play();
             //particles
             Instantiate(ParticleFX,newPosition + Vector3.up * 0.2f,Quaternion.identity);
             //do colorcheck in gamemanager
             G$$anonymous$$S.InitColorCheck();
         }
         else if (isdragged && hitCard) 
         {
             transform.position = newPosition;
             DT.transform.position = oldPosition;
             isdragged = false;
             //play sound
             CardAudio.clip = SwapClip;
             CardAudio.Play();
             //particles
             Instantiate(ParticleFX,newPosition + Vector3.up * 0.2f,Quaternion.identity);
             //do colorcheck in gamemanager
             G$$anonymous$$S.InitColorCheck();
 
         }
         else//just rotated
         {
             transform.position = oldPosition;
             isdragged = false;
             //play sound
             CardAudio.clip = RotateClip;
             CardAudio.Play();
             //Instantiate(ParticleFX,oldPosition + Vector3.up * 0.2f,Quaternion.identity);
 
             //do colorcheck in gamemanager
             //G$$anonymous$$S.InitColorCheck();
             //do it in rotatescript
             if(!RS.isRotating)
                 G$$anonymous$$S.InitColorCheck ();
                 Debug.Log ("rotation corouine fired");
         }
     }


I'll try your way with invoke.

avatar image Statement OctoMan · Nov 03, 2015 at 08:39 PM 0
Share

It shouldn't make a difference. But are you setting Card$$anonymous$$atches to zero? It seems that you just keep adding and adding matches. I don't know if that is correct behaviour? If you had 3 matches, drag something, and you still have 3 matches, your variable will now be 3+3.

avatar image OctoMan Statement · Nov 03, 2015 at 08:41 PM 0
Share

Yes is reset the Card$$anonymous$$atches on$$anonymous$$ouseDown()

and call this function from there:

 public void ResetCard$$anonymous$$atches()
     {
         //if (!gameWon) 
         {
             Card$$anonymous$$atches = 0;
             for (int i = 0; i < allcards.Length; i++) 
             {
                 allcards [i].GetComponent<ColorCheck> ().matches = 0;
                 //deactivate all highlights
                 allcards [i].GetComponent<ColorCheck> ().Highlight1.SetActive (false);
                 allcards [i].GetComponent<ColorCheck> ().Highlight2.SetActive (false);
             }
 
         }
     }

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

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

StartCoroutine still runs 1 more second after using yield break 1 Answer

IEnumerator when button is pressed 0 Answers

Flash Image once 1 Answer

void don't Run which tagged "Cmd" in IEnumrator :( 0 Answers

Do Slowmotion effect for x seconds 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