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 LuckierBread · Jul 14, 2016 at 09:46 PM · playertime

Play button not playing the game. BIG PROBLEM(Solved)

Today i loaded my project and nothing worked. the only thing i changed without testing the day before was adding a bool to a script that changed the players color.

Today when i hit play all of the codes run through their start functions then stop. the only script that is working is the color changer. everything else seems frozen in time.

I have tried disabling all the scripts except game controller and the problem persists.

I have looked over my code for hours and haven't found any issues with it. everything just stops for no reason. Please help.

UPDATE: more debugging has found that the update sections are only called once.

Game controller script.

 public GameObject[] hazardList;
 public GameObject restartButton;

 public int hazardCount;
 public int hazardCountIncrease;

 
 public float hazardSpeed;
 public float speedIncrease;
 public float startWait;
 public float spawnWait;
 public float waveWait;

 public Vector3 spawnArea1;
 public Vector3 spawnArea2;
 public Vector3 spawnArea3;

 public Text scoreText;
 public Text highScoreText;
 public Text gameOverScoreText;

 private bool gameOver;
 private float score;
 private GameObject hazard;



 void Start ()
 {
     restartButton.SetActive(false);
     gameOverScoreText.text = "";
     highScoreText.text = "";
     scoreText.text = "Score: " + 0;
     gameOver = false;

     StartCoroutine(HazardWaves(spawnArea1));
     StartCoroutine(HazardWaves(spawnArea2));
     StartCoroutine(HazardWaves(spawnArea3));
 }
 
 IEnumerator HazardWaves(Vector3 spawnArea)
 {
     yield return new WaitForSeconds(startWait);
     while (true)
     {
         //Base wave spawner
         for (int i = 0; i < hazardCount; i++)
         {
             GameObject hazard = hazardList[Random.Range(0, hazardList.Length)];
             Vector3 spawnPosition = new Vector3(Random.Range(spawnArea.x, spawnArea.x + 15), spawnArea.y, spawnArea.z);
             Quaternion spawnRotation = Quaternion.identity;
             Instantiate(hazard, spawnPosition, spawnRotation);
             yield return new WaitForSeconds(spawnWait);
         }
         hazardCount = hazardCount + hazardCountIncrease;
         hazardSpeed = hazardSpeed += speedIncrease;

         yield return new WaitForSeconds(waveWait);
         if (gameOver == true)
         {
             break;
         }
     }
 }

 void Update()
 {
     if (gameOver == false)
     {
         score = Time.timeSinceLevelLoad;
         scoreText.text = "Score: " + score.ToString("f2");
     }
     if (gameOver == true)
     {
         scoreText.text = "";
         gameOverScoreText.text = "Score: " + score.ToString("f2");
     }
 }
 // commented this section out to try and fight the bug but even with this gone the game stops after the start section.
 //public void GameOver()
 //{
 //    restartButton.SetActive(true);
  //   gameOver = true;
 //    Time.timeScale = 0;
 //}

 public void ResartGame()
 {
     score = 0;
     Time.timeScale = 1;
     Application.LoadLevel(Application.loadedLevel);
 }

 void SetHighScore(float score)
 {
     if (PlayerPrefs.HasKey("highScore"))
     {
         if (PlayerPrefs.GetFloat("highScore") <= score)
             PlayerPrefs.SetFloat("highScore", score);
     }
     else
     {
         PlayerPrefs.SetFloat("highScore", score);
     }
 }

Color Changer script.

 public bool isRed;
 public Renderer colorRenderer;

 void Start ()
 {
     isRed = false;
 }
 
 void Update ()
 {
     if (Input.touchCount > 0)
     { 
         if (Input.GetTouch(0).phase == TouchPhase.Began)
         {
             isRed = !isRed;
             if (isRed == true)
             {
                 colorRenderer.material.color = Color.red;
             }
             else
             {
                 colorRenderer.material.color = Color.blue;
             }
         
         }       
     }
 }
Comment
Add comment · Show 4
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 vintar · Jul 14, 2016 at 09:51 PM 0
Share

I guess check your public floats startWait, spawnWait and waveWait and see if they are big.

avatar image LuckierBread vintar · Jul 14, 2016 at 09:55 PM 0
Share

Each is 3 seconds but that doesn't explain why the other scripts that are completely separate stop as well. I have tried starting the game with obstacles spawned in and they all stop after a frame of movement. the script for moving is separate and confined to the hazard

avatar image vintar LuckierBread · Jul 14, 2016 at 10:00 PM 1
Share

If you have an IEnumerator without a yield, it will halt the entire game as Coroutines are not asynchronous. Check all yours and make sure they contain a yield.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LuckierBread · Jul 16, 2016 at 03:32 AM

So i never figured out what went wrong and stopped my player, but i tried making a new project then copying the assets folder from the first project and then loading the scene in that folder.

Now everything works.

If someone figures out what the issue was i would love to hear it so i can hopefully avoid it in the future.

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.

Follow this Question

Answers Answers and Comments

64 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

Related Questions

Fixing Animation calls in a combo Script 0 Answers

Move Player (y-Axis) on click button does not work 0 Answers

Is there a way to import Top/Down 360 stereo footage so that Unity can play it correctly through something like the google cardboard? 0 Answers

Hi, I would like my player to push away from a wall sort of like ninja game. After toying around a bit I'm stuck. Anyone got any tips? 0 Answers

IsPointerOverGameObject() returns Object reference not set to an instance of an object 2 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