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 surfuay · Nov 02, 2018 at 08:30 PM · unity 5scorecoroutinesscore systemspawning problems

Trying to get my spawn manager to respond to the current score

So my spawn manager is working well with anything that does not need to respond to the current score.

My problem is that I want certain gameObjects to spawn based on what my current score is but it's not going well. I do have all my gameObjects properly attached to scripts, canvas etc.

I'm trying to call the score from the UIManager into my Spawn Manager to start the coroutine when the score is greater than or equal to 50.

UI Manager code: contains the score and updating of score.

public Text scoreText; public int score;

public void UpdateScore() { score += 10; scoreText.text = "Score:" + score; }

Spawn Manager Code: is calling to the uiManager to start the coroutine ArcherSpawnManager, the first 2 coroutines are working fine as the simply begin regardless of anything.

private UIManager _uIManager;

 void Start()
 {
     _uIManager = GameObject.Find("Canvas").GetComponent<UIManager>();

     StartCoroutine(MerchantSpawnRoutine());
     StartCoroutine(PowerUpsSpawnRoutine());
     if (_uIManager.score >= 50)
     {
         StartCoroutine(ArcherSpawnRoutine());
     }
 }


public IEnumerator ArcherSpawnRoutine() {

         while (true)
         {
             yield return new WaitForSeconds(Random.Range(2, 4));
             Instantiate(_archerBottomRight, new Vector3(8.2f, Random.Range(-4.25f, -.5f), 0), Quaternion.identity);

             yield return new WaitForSeconds(Random.Range(2, 4));
             Instantiate(_archerBottomLeft, new Vector3(-8.2f, Random.Range(-4.25f, -.5f), 0), Quaternion.identity);

             yield return new WaitForSeconds(Random.Range(2, 4));
             Instantiate(_archerTopRight, new Vector3(8.05f, Random.Range(.5f, 4.25f), 0), Quaternion.identity);

             yield return new WaitForSeconds(Random.Range(2, 4));
             Instantiate(_archerTopLeft, new Vector3(-8.11f, Random.Range(.5f, 4.25f), 0), Quaternion.identity);
         }

     

 }
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
Best Answer

Answer by AaronXRDev · Nov 02, 2018 at 08:49 PM

I would put the score check inside the ArcherSpawnRoutine instead of on Start. I would expect that at the start the player's score would always be 0.

         while (true)
         {
             yield return new WaitForSeconds(Random.Range(2, 4));
             if (_uIManager.score >= 50) { Instantiate(_archerBottomRight, new Vector3(8.2f, Random.Range(-4.25f, -.5f), 0), Quaternion.identity); }
             yield return new WaitForSeconds(Random.Range(2, 4));
             if (_uIManager.score >= 50) { Instantiate(_archerBottomLeft, new Vector3(-8.2f, Random.Range(-4.25f, -.5f), 0), Quaternion.identity); }
             yield return new WaitForSeconds(Random.Range(2, 4));
             if (_uIManager.score >= 50) { Instantiate(_archerTopRight, new Vector3(8.05f, Random.Range(.5f, 4.25f), 0), Quaternion.identity); }
             yield return new WaitForSeconds(Random.Range(2, 4));
             if (_uIManager.score >= 50) { Instantiate(_archerTopLeft, new Vector3(-8.11f, Random.Range(.5f, 4.25f), 0), Quaternion.identity); }
         }
Comment
Add comment · Show 1 · 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 surfuay · Nov 02, 2018 at 09:00 PM 0
Share

NO WAY! It finally worked. Thank you so much, this has been driving me up a wall for hours!

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

186 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

Related Questions

in this code whenever score is gretater than highscore then old highscore becomes zero and after the game ends it get updated 0 Answers

Object falling over triggers way too many times 0 Answers

I am trying to add additional score to my current timed score but cannot find how to do this 0 Answers

Storing high score 2 Answers

How to add score after destroying object in unity 2D? 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