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 /
avatar image
0
Question by Eagle-Bound · Sep 23, 2016 at 08:23 PM · c#noobbreak

Short Break Between Sequence of Colors

In my really simple simon says type game, there is a sequence of colors the player has to match. The only problem is when the computer decides if the player answers correctly, it instantly goes to the next sequence. I would like to have the game wait for a second before going on to the next sequence, but I don't know how. If anyone knows why, I would appreciate it if you let me know. My script:

     public void ColorPressed(int whichButton){
 
         if (activeSequence [inputInSequence] == whichButton) {
             if (gameActive) {
                 Debug.Log ("Correct");
                 waitBetweenLevels -= Time.deltaTime;
                 inputInSequence++;
             }
             if (inputInSequence >= activeSequence.Count) {
                 if (activeSequence.Count > PlayerPrefs.GetInt ("EasyHighScore")) {
                     PlayerPrefs.SetInt ("EasyHighScore", activeSequence.Count);
                 }
                 scoreText.text = "Score: " + activeSequence.Count + "- High Score: " + PlayerPrefs.GetInt ("EasyHighScore");
                 posInSequence = 0;
                 inputInSequence = 0;
                 colorSelect = Random.Range (0, colors.Length);
                 activeSequence.Add (colorSelect);
                 colors [activeSequence [posInSequence]].color = new Color (colors [activeSequence [posInSequence]].color.r, colors [activeSequence [posInSequence]].color.g, colors [activeSequence [posInSequence]].color.b, 1f);
                 buttonSounds [activeSequence [posInSequence]].Play ();
                 litCounter = lit;
                 shouldBeLit = true;
                 gameActive = false;
                 correct.Play ();
                 //Break Here
             }  

         
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

Answer by elenzil · Sep 23, 2016 at 10:55 PM

your example has a ton of code, so i haven't read it. (in general folks are more likely to read code you post when it's the minimal amount of code which demonstrates the problem you're having)

but this sounds like a good use for a coroutine. coroutines are perfect for sequences of things with pauses included.

here's an example.

 void doSomeStuff() {
   // this is a normal routine, and will return like normal
 
   StartCoroutine(myCR("hello"));
 
   // execution flows straight through to here after _starting_ the coroutine.
   // ie, in this function, execution does not wait for the coroutine to finish.
 }
 
 IEnumerator myCR(string exampleParameter) {
   Debug.log("here's a line");
   yield return new WaitForSeconds(2);
   Debug.log("here's a line 2 seconds later. also here's that parameter: " + exampleParameter);
 }
Comment
Add comment · Show 5 · 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 Eagle-Bound · Sep 23, 2016 at 11:27 PM 0
Share

Thanks! I tried doing something like this, but unless I was doing something, it gave me an error. Is it possible that the error was caused because I'm trying to put it in my public void ColorePressed() ? And if so, how you go about doing it?

avatar image Eagle-Bound Eagle-Bound · Sep 29, 2016 at 06:35 PM 0
Share

I also shortened the code to the area I think is the most important to this question

avatar image elenzil Eagle-Bound · Sep 29, 2016 at 07:04 PM 0
Share

good job shortening. what error ?

try getting a basic coroutine like the one i sketched above working, and then changing it gradually into what you want, and see at what point you run into a problem.

Show more comments

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

224 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Literally just started coding in c#, having error cs1729 1 Answer

My Animation Loops 3/4 of the way through 3 Answers

Modify friction behavior on Physics 2D Material 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