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 weaselbone · May 19, 2020 at 11:07 AM · crashingfreezing

Unity editor freezes when playing, i think it's the loops

I'm trying to make a loop, what it does is it'll generate a number, and then checks if the number(ID) is disabled or not if it is it'll loop and makes one again. the thing is that it has a break when the generated number is not disabled, so I'm guessing the loop couldn't find the number and keep looping infinitely?

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class NoteGenerator : MonoBehaviour { public Sprite slot1; public Sprite slot2; public Sprite slot3;

 public AudioSource Note1;
 public AudioSource Note2;
 public AudioSource Note3;

 public AudioSource metronomeTick;

 public AudioClip S_Slot1;
 public AudioClip S_Slot2;
 public AudioClip S_Slot3;

 public Animator ani;
 public GameObject BoxCursor;

 #region note selection

 public bool[] NoteSelectedByUser = new bool[3]; // nomornya itu berapa banyak note div 

 #endregion


 #region debugging



 #endregion

 public int selectedNote1;
 public int selectedNote2;
 public int selectedNote3;

 public int selectedDevision1;
 public int selectedDevision2;
 public int selectedDevision3;

 public bool canGenerate;

 public string[, ,] noteLists = new string[3, 12, 2]; // inget tambah satu krna integer mulai dari 0

 private int noteListLength;


 // 0 = 8ths,  1 = triplets,  2 = 16ths,  3 = quintuplets (ntar aj dulu yg 2,3,4)

 void Start()
 {

     canGenerate = true;

     ani.enabled = false;
     BoxCursor.GetComponent<Image>().enabled = false;


     #region note lists

     #region 8th notes [0]
     noteLists[0, 0, 0] = "all_8th_I"; noteLists[0, 0, 1] = "all_8th_S";
     noteLists[0, 1, 0] = "1_8th_I"; noteLists[0, 1, 1] = "1_8th_S";
     noteLists[0, 2, 0] = "2_8th_I"; noteLists[0, 2, 1] = "2_8th_S";
     #endregion 8

     #region 16th notes [1]
     noteLists[1, 0, 0] = "all_16th_I"; noteLists[1, 0, 1] = "all_16th_S";


     #region 1 note only
     // - 1 16th sama dgn 1 8th
     noteLists[1, 1, 0] = "2_16th_I"; noteLists[1, 1, 1] = "2_16th_S";
     // - 3 16th sama dgn 2 8th
     noteLists[1, 2, 0] = "4_16th_I"; noteLists[1, 2, 1] = "4_16th_S";
     #endregion

     #region 2 notes only
     noteLists[1, 3, 0] = "1n2_16th_I"; noteLists[1, 3, 1] = "1n2_16th_S";
     //- 1n3 sama dengan all 8th
     noteLists[1, 4, 0] = "1n4_16th_I"; noteLists[1, 4, 1] = "1n4_16th_S";
     noteLists[1, 5, 0] = "2n3_16th_I"; noteLists[1, 5, 1] = "2n3_16th_S";
     noteLists[1, 6, 0] = "2n4_16th_I"; noteLists[1, 6, 1] = "2n4_16th_S";
     noteLists[1, 7, 0] = "3n4_16th_I"; noteLists[1, 7, 1] = "3n4_16th_S";
     #endregion

     #region 3 notes only
     noteLists[1, 8, 0] = "1n2n3_16th_I"; noteLists[1, 8, 1] = "1n2n3_16th_S";
     noteLists[1, 9, 0] = "2n3n4_16th_I"; noteLists[1, 9, 1] = "2n3n4_16th_S";
     noteLists[1, 10, 0] = "1n3n4_16th_I"; noteLists[1, 10, 1] = "1n3n4_16th_S";
     noteLists[1, 11, 0] = "1n2n4_16th_I"; noteLists[1, 11, 1] = "1n2n4_16th_S";
     #endregion
     #endregion 16

     #region Triplets [2]
     noteLists[2, 0, 0] = "all_3plets_I"; noteLists[2, 0, 1] = "all_3plets_S";

     #region 1 note only
     noteLists[2, 1, 0] = "1_3plets_I"; noteLists[2, 1, 1] = "1_3plets_S";
     noteLists[2, 2, 0] = "2_3plets_I"; noteLists[2, 2, 1] = "2_3plets_S";
     noteLists[2, 3, 0] = "3_3plets_I"; noteLists[2, 3, 1] = "3_3plets_S";
     #endregion

     #region 2 note only
     noteLists[2, 4, 0] = "1n2_3plets_I"; noteLists[2, 4, 1] = "1n2_3plets_S";
     noteLists[2, 5, 0] = "2n3_3plets_I"; noteLists[2, 5, 1] = "2n3_3plets_S";
     noteLists[2, 6, 0] = "1n3_3plets_I"; noteLists[2, 6, 1] = "1n3_3plets_S";
     #endregion 

     #endregion 3plet

     #endregion list

     GenerateNotes();

     NoteSelectedByUser[0] = true;
     NoteSelectedByUser[1] = true;
     NoteSelectedByUser[2] = true;
 }


 public void GenerateNotes()
 {

  

     for (bool f = false; f == false;) //f for found
     {
         selectedDevision1 = Random.Range(0, 3);
         if (NoteSelectedByUser[selectedDevision1] == true)
         {
             f = true;
             

             if (selectedDevision1 == 0) // buat 8th
                 selectedNote1 = Random.Range(0, 3);

             if (selectedDevision1 == 1) // buat 16th
                 selectedNote1 = Random.Range(0, 12);

             if (selectedDevision1 == 2) // buat 3plet
                 selectedNote1 = Random.Range(0, 7);

             // urutan index [devision, enabled note, (0 = image/sprite) (1 = soundfile)]


             slot1 = Resources.Load(noteLists[selectedDevision1, selectedNote1, 0], typeof(Sprite)) as Sprite;
             Note1.clip = Resources.Load(noteLists[selectedDevision1, selectedNote1, 1], typeof(AudioClip)) as AudioClip;
             break;
         }

          

     }


      
     







     for (bool f = false; f == false;) //f for found
     {
         selectedDevision2 = Random.Range(0, 3);
         if (NoteSelectedByUser[selectedDevision2] == true)
         {               
             f = true;
             

             if (selectedDevision2 == 0) // buat 8th
                 selectedNote2 = Random.Range(0, 3);

             if (selectedDevision2 == 1) // buat 16th
                 selectedNote2 = Random.Range(0, 12);

             if (selectedDevision2 == 2) // buat 3plet
                 selectedNote2 = Random.Range(0, 7);


             slot2 = Resources.Load(noteLists[selectedDevision2, selectedNote2, 0], typeof(Sprite)) as Sprite;
             Note2.clip = Resources.Load(noteLists[selectedDevision2, selectedNote2, 1], typeof(AudioClip)) as AudioClip;
             break;
         }


     }


     







     for (bool f = false; f == false;) //f for found
     {
         selectedDevision3 = Random.Range(0, 3);
         if (NoteSelectedByUser[selectedDevision3] == true)
         {
             f = true;
             

             if (selectedDevision3 == 0) // buat 8th
                 selectedNote3 = Random.Range(0, 3);

             if (selectedDevision3 == 1) // buat 16th
                 selectedNote3 = Random.Range(0, 12);

             if (selectedDevision3 == 2) // buat 3plet
                 selectedNote3 = Random.Range(0, 7);


             slot3 = Resources.Load(noteLists[selectedDevision3, selectedNote3, 0], typeof(Sprite)) as Sprite;
             Note3.clip = Resources.Load(noteLists[selectedDevision3, selectedNote3, 1], typeof(AudioClip)) as AudioClip;

             break;
         }


     }

    

 }


 public void PlayAnimNots()
 {
     BoxCursor.GetComponent<Image>().enabled = true;
     ani.enabled = true;
     ani.SetBool("open", true);

     canGenerate = false;

     UnityEngine.Debug.Log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
 }

 public void AnimationEnd()
 {
     BoxCursor.GetComponent<Image>().enabled = false;
     ani.enabled = false;
     ani.Play("doNothing", 0, 0.0f);
     ani.SetBool("open", true);

     canGenerate = true;
 }




 public void PlayNotes1()
 {
     Debug.Log("first note played");
     Note1.Play();
     metronomeTick.Play();
 }

 public void PlayNotes2()
 {
     Debug.Log("second note played");
     Note2.Play();
     metronomeTick.Play();
 }

 public void PlayNotes3()
 {
     Debug.Log("third note played");
     Note3.Play();
     metronomeTick.Play();
 }

}

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 weaselbone · May 18, 2020 at 10:54 AM 0
Share

lmao found the issue, so I forgot to set at least one enabled number in NoteSelectedByUser. and on top of that, the user can disable all number which broke the app entirely lmaooo

0 Replies

· Add your reply
  • Sort: 

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

200 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

Related Questions

Unity causes computer to crash/freeze. 1 Answer

Unity freezes when I run this and I have no idea why, please help 0 Answers

Cinemachine crashes unity 1 Answer

My Unity Keeps freezing; Windows 7 0 Answers

How to fix these problems? 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