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 /
This question was closed Nov 13, 2016 at 01:28 AM by AngryKiwiArts for the following reason:

Too subjective and argumentative

avatar image
0
Question by AngryKiwiArts · Nov 12, 2016 at 10:30 PM · coroutineslong

Strange Problems in long scripts

I made a game and it was working fine until i added in a few more functions. It seems that my code is skipping my coroutine, its not checking for score or strike changes and the ValueID isnt changing. I know its a big script but if anyone has any ideas, please let me know.

 public  Text strikeAmount;
     public Font fontGoestHere;
     public int strikebebug;
     public int valueID; //checks red zone values
     public bool executing = false; //turns on rezones
     public int points;
     public float speed;
     //first level is actually level 0
     public  bool lvl1unlocked = false;
     public  bool lvl2unlocked = false;
     public  bool lvl3unlocked = false;
     public  GameObject[] talk;
     public  GameObject[] talk1;
     public  GameObject[] talk2;
     public  GameObject[] hit;
     public  GameObject[] hit1;
     public  GameObject[] hit2;
     public  GameObject[] interupt;
     public  GameObject[] interupt1;
 
     public  GameObject[] interuptFinish;
     public  GameObject[] interuptFinish1;
 
 
 
     public bool redZone = false;
     public int strike = 0; // adds 1 if you miss red zone 3 strikes and gg?
     public bool hasSlapped = false; // checks if you slapped during red zone
     public AudioSource speech;
     public AudioSource interruption;
     public AudioSource thump;
     public AudioClip [] Speechclips;
     public AudioClip [] Speech1clips;
     public AudioClip [] Speech2clips;
     public AudioClip [] clipsInt;
     public AudioClip [] clipsIntFinish;
 
     public AudioClip[] clipsThump;
     public AudioClip[] clipsThump1;
     public AudioClip[] clipsThump2;
     public int currentObject;
     public  int clipPick;
     public int thumpPick;
     public int intPick;
     public bool endredzone;
     public float timeLeft = 56;
     public bool IsInterrupting = false;
     public bool IsThumping = false;
     public bool IsSpeeching = false;
     public int speechlevel1Pick;
     public int speechlevel2Pick;
     public int speechlevel3Pick;
 
 
     // Use this for initialization
     public void Start()
     {
         speech = GetComponent<AudioSource>();
 //        speech.Play ();
         strike = strikebebug;
         StartRedzone ();
     }
 
 
     void Update ()
     {
         if (Input.GetKeyDown("f")) {
             StartCoroutine("StartRedzone");
         }
         //                StartCoroutine(Leveltime());
         timeLeft -= Time.deltaTime;
         if (timeLeft < 0) {
             if (Application.loadedLevel == 1) {
                 if (points > 666) {
                     //speed=.8f;
                     lvl1unlocked = true;
                 }
             }
             if (Application.loadedLevel == 2) {
                 if (points > 1337) {
                     //speed=.6f;
                     lvl2unlocked = true;
                 }
             }
             if (Application.loadedLevel == 3) {
                 if (points > 1992) {
                     //speed=.6f;
                     lvl3unlocked = true;
                 }
             }
             CheckGameOver ();
         }
 
         Debug.Log (speech.time);
         Debug.Log (interruption.time);
         Debug.Log (thump.time);
         //this is where i used to start the redzone
         if (executing == false) {
             StartCoroutine (StartRedzone ());
         }
         if (Application.loadedLevel == 1) {
             switch (clipPick) {
             case 0:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 1:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 2:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 3:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 4:
                 if (speech.time > 3f && endredzone == false)
                     redZone = true;
                 break;
             case 5:
                 if (speech.time > 4f && endredzone == false)
                     redZone = true;
                 break;
             case 6:
                 if (speech.time > 5f && endredzone == false)
                     redZone = true;
                 break;
             case 7:
                 if (speech.time > 5f && endredzone == false)
                     redZone = true;
                 break;
             case 8:
                 if (speech.time > 5f && endredzone == false)
                     redZone = true;
                 break;
             case 9:
                 if (speech.time > 6f && endredzone == false)
                     redZone = true;
                 break;
             case 10:
                 if (speech.time > 7f && endredzone == false)
                     redZone = true;
                 break;
             case 11:
                 if (speech.time > 7f && endredzone == false)
                     redZone = true;
                 break;
             }
         }
         if (Application.loadedLevel == 2) {
             switch (clipPick) {
             case 0:
                 if (speech.time > 1f && endredzone == false)
                     redZone = true;
                 break;
             case 1:
                 if (speech.time > 1f && endredzone == false)
                     redZone = true;
                 break;
             case 2:
                 if (speech.time > 1f && endredzone == false)
                     redZone = true;
                 break;
             case 3:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 4:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 5:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 6:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 7:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 8:
                 if (speech.time > 1f && endredzone == false)
                     redZone = true;
                 break;
             case 9:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 10:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 11:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             }
         }
         if (Application.loadedLevel == 3) {
             switch (clipPick) {
             case 0:
                 if (speech.time > 1f && endredzone == false)
                     redZone = true;
                 break;
             case 1:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 2:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 break;
             case 3:
                 if (speech.time > 3f && endredzone == false)
                     redZone = true;
                 break;
             case 4:
                 if (speech.time > 4f && endredzone == false)
                     redZone = true;
                 break;
             case 5:
                 if (speech.time > 5f && endredzone == false)
                     redZone = true;
                 break;
             case 6:
                 if (speech.time > 4f && endredzone == false)
                     redZone = true;
                 break;
             case 7:
                 if (speech.time > 1f && endredzone == false)
                     redZone = true;
                 break;
             case 8:
                 if (speech.time > 2f && endredzone == false)
                     redZone = true;
                 if (speech.time > 7f && endredzone == false)
                     redZone = true;
                 break;
             case 9:
                 if (speech.time > 5f && endredzone == false)
                     redZone = true;
                 break;
             case 10:
                 if (speech.time > 5f && endredzone == false)
                     redZone = true;
                 break;
             case 11:
                 if (speech.time > 8f && endredzone == false)
                     redZone = true;
                 break;
             }
         }
         
         if (valueID == 2) {
             gameObject.GetComponent<Renderer> ().material.color = Color.red;
         }    //re
         if (valueID == 1) {
             gameObject.GetComponent<Renderer> ().material.color = Color.yellow;
         }    //yellow
         if (valueID == 3) {
             gameObject.GetComponent<Renderer> ().material.color = Color.yellow;
         }    //yellow
         if (valueID == 0) {
             gameObject.GetComponent<Renderer> ().material.color = Color.white;
         }    //white
         if (valueID == 5) {
             gameObject.GetComponent<Renderer> ().material.color = Color.white;
         }    //white
         //colors the "lightbulb"
 
                 if (speech.isPlaying) {
                     IsSpeeching = true;
                 }
         if (Input.GetButtonDown ("Fire1")) {
             if (redZone == true) {
                         if (valueID == 0) {
                     strike++;
                     points -= 10;
                 }
                 if (valueID == 1) {
                     points += 25;
                 }
                 if (valueID == 2) {
                     points += 25;
                 }
                 if (valueID == 3) {
                     points += 50;
                 }
                 if (valueID == 4) {
                     strike++;
                     points -= 10;
                 }
                 IsSpeeching = false;
                 PlayingThump ();
                 hasSlapped = true;
         
             }
             
             if (redZone == false) {
                 IsSpeeching = false;
 
                 int randomIntPick = Random.Range (0, 1);
                 if(randomIntPick == 0){
                 PlayingInterruption ();
                 }
                 if(randomIntPick == 1){
                     PlayingFinish ();
                 }
 
 
                 AddStrike ();
                 
             }
             //end audio animation
             
             if (points < 0) {
                 points = 0;
             }
             
             if (strike == 0) {
                 strikeAmount.text = "";
             }
             if (strike == 1) {
                 strikeAmount.text = "x";
             }
             if (strike == 2) {
                 strikeAmount.text = "xx";
             }
             if (strike == 3) {
                 strikeAmount.text = "xxx";    
                 Application.LoadLevel (4);
             }
             if (strike > 3) {
                 strikeAmount.text = "xxx";    
                 Application.LoadLevel (4);
             }
         }
 
         //if speech expires and isnt on
                     if (speech.time == 0 || interruption.time == 0 || thump.time == 0 && IsSpeeching == false)
                     {
                     endredzone = false;
                     redZone = false;
                     }
         //if audio hit is playing and youre not in the middle of a hit
                 if (thump.isPlaying) 
                 {
                     IsThumping = true;
                 }
         //
                 if (interruption.isPlaying) 
                 {
                     IsInterrupting = true;
                 }
 
 
 
         if (!thump.isPlaying) {
             UnPauseSpeech();
             if (Application.loadedLevel == 1) {
                 foreach (GameObject obj in hit) {
                     obj.SetActive (false);}
 //                talk [speechlevel1Pick].SetActive (true);
             }
             if (Application.loadedLevel == 2) {
                 foreach (GameObject obj in hit1) {
                     obj.SetActive (false);}
 //                    talk1 [speechlevel2Pick].SetActive (true);
             }
             if (Application.loadedLevel == 3) {
                 foreach (GameObject obj in hit2) {
                     obj.SetActive (false);}
 //                talk2 [speechlevel3Pick].SetActive (true);
             }
             PlayingSpeech();
             IsThumping = false;
         }
 
         if (!interruption.isPlaying) {
             UnPauseSpeech();
             foreach (GameObject obj in interupt) {
                 obj.SetActive (false);
                 if (Application.loadedLevel == 1) {
                     talk [speechlevel1Pick].SetActive (true);
                 }
                 if(Application.loadedLevel == 2) {
                     talk1 [speechlevel2Pick].SetActive (true);
                 }
                 if(Application.loadedLevel == 3) {
                     talk2 [speechlevel3Pick].SetActive (true);
                 }
 
             }
             PlayingSpeech();
             IsInterrupting = false;
         }
 
         if (thump.isPlaying) {
             speech.Pause();
 
         }
         if (interruption.isPlaying) {
             speech.Pause();
         }
 
 
 
     }
 
     IEnumerator StartRedzone(){
         executing = true;
         if (redZone) {
             valueID++;
         }
         yield return new WaitForSeconds (speed);
         Debug.Log("Passed seconds");
         
         if(valueID == 5){
             endredzone = true;
             valueID = 0;
             redZone = false;
             if(!hasSlapped){AddStrike();}
             hasSlapped = false;
         }
         executing = false;
     }
 
     void PlayingThump()
     {
         IsThumping = true;
         IsSpeeching = false;
         IsInterrupting = false;
 
 
     
         if (Application.loadedLevel == 1) {
             foreach (GameObject obj in hit) {
         obj.SetActive(false);}
             foreach (GameObject objj in talk) {
                 objj.SetActive(false);}
         int thumplevel1Pick = Random.Range (0, hit.Length);
         hit [thumplevel1Pick].SetActive (true);
         int thumpLevel1Pick = Random.Range (0, clipsThump.Length);
         thump.clip = clipsThump [thumpLevel1Pick];
         }
         
         if(Application.loadedLevel == 2) {
             foreach (GameObject obj in hit1) {
             obj.SetActive (false);} 
             foreach (GameObject objj in talk1) {
                 objj.SetActive(false);}
         int thumplevel2Pick = Random.Range (0, hit1.Length);
         hit1 [thumplevel2Pick].SetActive (true);
         int thumpLevel2Pick = Random.Range (0, clipsThump1.Length);
         thump.clip = clipsThump1 [thumpLevel2Pick];
     ;
         }
         
         
         if(Application.loadedLevel == 3) {
             foreach (GameObject obj in hit2) {
             obj.SetActive (false);}
             foreach (GameObject objj in talk2) {
                 objj.SetActive(false);}
         int thumplevel3Pick = Random.Range (0, hit1.Length);
         hit1 [thumplevel3Pick].SetActive (true);
         int thumpLevel3Pick = Random.Range (0, clipsThump2.Length);
         thump.clip = clipsThump2 [thumpLevel3Pick];
         
 
         }
         speech.Pause ();
         thump.Play ();
 //        IsThumping = false;
     }
 
 
     void PlayingInterruption(){
         IsSpeeching = false;
         IsThumping = false;
         IsInterrupting = true;
             foreach (GameObject obj in interupt) {
             obj.SetActive(false);}
         foreach (GameObject objj in talk) {
             objj.SetActive(false);}
         foreach (GameObject objj in interuptFinish) {
             objj.SetActive(false);}
 
 
         if (Application.loadedLevel == 1) {
         foreach (GameObject obj in talk) {
             obj.SetActive(false);}
         int dodgelevel1Pick = Random.Range (0, interupt.Length);
             interupt [dodgelevel1Pick].SetActive (true);
             int interruptionLevel1Pick = Random.Range (0, clipsInt.Length);//dodges need seperated
             interruption.clip = clipsInt [interruptionLevel1Pick];
         }
         
         if (Application.loadedLevel == 2) {
             foreach (GameObject obj in talk1) {
                 obj.SetActive (false);}
             int dodgelevel2Pick = Random.Range (0, interupt.Length);
             interupt [dodgelevel2Pick].SetActive (true);
             int interruptionLevel2Pick = Random.Range (0, clipsInt.Length);
             interruption.clip = clipsInt [interruptionLevel2Pick];
         }
 
         if(Application.loadedLevel == 3) {
             foreach (GameObject obj in hit2) {
                 obj.SetActive (false);}
             foreach (GameObject obj in talk2) {
                 obj.SetActive(false);}
             int thumplevel3Pick = Random.Range (0, hit1.Length);
             hit1 [thumplevel3Pick].SetActive (true);
             int thumpLevel3Pick = Random.Range (0, clipsThump2.Length);
             thump.clip = clipsThump2 [thumpLevel3Pick];
             
             
         }
         speech.Pause ();
         interruption.Play ();
     }
 
     void PlayingFinish(){
         IsSpeeching = false;
         IsThumping = false;
         IsInterrupting = true;
         
         if (Application.loadedLevel == 1) {
             foreach (GameObject obj in interupt) {
                 obj.SetActive(false);}
             foreach (GameObject objj in interuptFinish) {
                 objj.SetActive(false);}
             foreach (GameObject objjj in talk) {
                 objjj.SetActive(false);}
             int dodgelevel1Pick = Random.Range (0, interupt.Length);
             interupt [dodgelevel1Pick].SetActive (true);
             int interruptionLevel1Pick = Random.Range (0, clipsInt.Length);//dodges need seperated
             interruption.clip = clipsInt [interruptionLevel1Pick];
         }
         
         if (Application.loadedLevel == 2) {
             foreach (GameObject obj in interupt1) {
                 obj.SetActive(false);}
             foreach (GameObject obj in interuptFinish1) {
                 obj.SetActive(false);}
             foreach (GameObject obj in talk1) {
                 obj.SetActive (false);}
             int dodgelevel2Pick = Random.Range (0, interupt.Length);
             interupt [dodgelevel2Pick].SetActive (true);
             int interruptionLevel2Pick = Random.Range (0, clipsInt.Length);
             interruption.clip = clipsInt [interruptionLevel2Pick];
         }
         
         if(Application.loadedLevel == 3) {
             foreach (GameObject obj in hit2) {
                 obj.SetActive (false);}
             foreach (GameObject obj in talk2) {
                 obj.SetActive(false);}
             int thumplevel3Pick = Random.Range (0, hit1.Length);
             hit1 [thumplevel3Pick].SetActive (true);
             int thumpLevel3Pick = Random.Range (0, clipsThump2.Length);
             thump.clip = clipsThump2 [thumpLevel3Pick];
             
             
         }
         speech.Pause ();
         interruption.Play ();
     }
 
     void PlayingSpeech(){
         IsSpeeching = true;
         IsInterrupting = false;
         IsThumping = false;
         if (speech.time == 0) {
         
         if (Application.loadedLevel == 1) {
             foreach (GameObject obj in talk) {
                 obj.SetActive(false);}
             int speechlevel1Pick = Random.Range (0, talk.Length);
             talk [speechlevel1Pick].SetActive (true);
             int clipPick = Random.Range (0, Speechclips.Length);
             speech.clip = Speechclips [clipPick];    
         }
         if(Application.loadedLevel == 2) {
             foreach (GameObject obj in talk1) {
                 obj.SetActive (false);} 
             int speechlevel2Pick = Random.Range (0, talk1.Length);
             talk1 [speechlevel2Pick].SetActive (true);
             int clipPick = Random.Range (0, Speech1clips.Length);
             speech.clip = Speech1clips [clipPick];            }
         if(Application.loadedLevel == 3) {
             foreach (GameObject obj in talk2) {
                 obj.SetActive (false);}
             int speechlevel3Pick = Random.Range (0, talk2.Length);
             talk2 [speechlevel3Pick].SetActive (true);
             int clipPick = Random.Range (0, Speech2clips.Length);
             speech.clip = Speech2clips [clipPick];    
         }
             speech.Play ();
         }
         else{speech.UnPause();}
 
     }
 
         void AddStrike(){
             strike++;
         }
 
 void CheckGameOver(){
         //gameover level 1
         if (Application.loadedLevel == 1 && lvl1unlocked == false) 
         {
             points = 0;
             timeLeft = 60;
             strike = 0;
             Application.LoadLevel (4);
         }
         //beat level 1
         if (Application.loadedLevel == 1 && lvl1unlocked == true) 
         {
             timeLeft = 60;
             speed = .9f;
             strike = 0;
             Application.LoadLevel (2);
         }
         if (Application.loadedLevel == 2 && lvl2unlocked == false) 
         {
             points = 0;
             timeLeft = 60;
             strike = 0;
             
             Application.LoadLevel (4);
         }
         if (Application.loadedLevel == 2 && lvl2unlocked == true) 
         {
             timeLeft = 60;
             speed = .8f;
             strike = 0;
 
             Application.LoadLevel (3);
         }
         if (Application.loadedLevel == 2 && lvl3unlocked == true) 
         {
             points = 0;
             timeLeft = 60;
             strike = 0;
             
             Application.LoadLevel (4);
         }
         if (Application.loadedLevel == 3 && lvl3unlocked == false) 
         {
             timeLeft = 60;
             speed = .8f;
             strike = 0;
 
             Application.LoadLevel (5);
         }
     }
     
     void UpdateScore ()
     {
         strikeAmount.text = "";
     }
     
     void OnGUI() 
     {
         GUI.skin.label.font = fontGoestHere;
         GUI.skin.label.fontSize = 20;
         GUI.Label (new Rect (20, 10, 150, 100), "Score " + points.ToString ());
         GUI.Label (new Rect (20, 30, 150, 60), "time " + timeLeft.ToString("N0")) ;
         
         //clip time display
 //        GUI.Label (new Rect (50, 150, 200, 100), "speech timer" + speech.time.ToString());
 //        GUI.Label (new Rect (50, 200, 200, 100), "interuption timer " + interruption.time.ToString());
 //        GUI.Label (new Rect (50, 250, 200, 100), "thump timer" + thump.time.ToString());
     }
     void UnPauseSpeech(){
         speech.UnPause ();
         IsSpeeching = true;
     }
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

77 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

Related Questions

using coroutine with fixedupdate and time. 0 Answers

Disabling jump for 0.25 sec after you hit the ground after jumping? 1 Answer

How to stop audio in coroutine unity 0 Answers

I have a top down shooter and this enemy script is giving me a massive headace, I would deeply appreciate help from anyone. Details are at the top of the code!! 1 Answer

How to prevent a method from delaying Update()? 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