Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ZLR_Games · Aug 05, 2020 at 11:19 PM · time.time

Why is my game not exporting correctly?

So I'm making a game where i have a spawner that only spawns certain prefabs, until a certain amount of time has passed. There are two times where it starts spawning more types of prefabs. Once after 5 seconds, and then when 30 seconds has passed, It unlocks even more things to be spawned. This works fine in the editor...but...when i export the game it doesn't work. When the 5 seconds pass, the new prefabs are spawned, but after 30 seconds...nothing. It just stays like it is. This is really annoying, cause i really need this to work, since these prefabs add a lot of variation to my game. (Don't want to give too many details)

So the way i actully do this is(example):

 public GameObject prefab1;
 public GameObject prefab2;
 public GameObject prefab3;
 public GameObject prefab4;
 public GameObject prefab5;
 public float rate = 2f;
 public float nextSpawn = 0f;
 public int whatToSpawn;

 public float narrowTime = 30f;
 public float movingTime = 5f;

 void Update()
 {
     if (Time.time >= nextSpawn)
     {
         if (Time.time >= narrowTime)
         {
             whatToSpawn = Random.Range(1, 6);

             switch (whatToSpawn)
             {
                 case 1:
                     Instantiate(prefab1, Transform.position, Quaternion.identity);
                     break;

                 case 2:
                     Instantiate(prefab2, Transform.position, Quaternion.identity);
                     break;

                 case 3:
                     Instantiate(prefab3, Transform.position, Quaternion.identity);
                     break;

                 case 4:
                     Instantiate(prefab4, Transform.positon, Quaternion.identity);
                     break;

                 case 5:
                     Instantiate(prefab5, Transform.position, Quaternion.Identity);
                     break;
             }


         }

         else if (Time.time >= movingTime)
         {
             whatToSpawn = Random.Range(1, 4);

             switch (whatToSpawn)
             {
                 case 1:
                     Instantiate(prefab1, Transform.position, Quaternion.identity);
                     break;

                 case 2:
                     Intsantiate(prefab2, Transform.position, Quaternion.identity);
                     break;

                 case 3:
                     Instantiate(prefab3, Tranform.position, Quaternion.identity);
                     break;
             }
         }

         else
         {
             whatToSpawn = Random.Range(1, 3);

             switch (whatToSpawn)
             {
                 case 1:
                     Instantiate(prefab1, Transform.position, Quaternion.identity);
                     break;

                 case 2:
                     Instantiate(prefab2, Transform.position, Quaternion.identity);
                     break;
             }
         }

             nextSpawn = Time.time + rate;
     }
 }

So basically i have a variable with the value of 5, and one with 30. I check if the in game time has reached, or gone above, that value yet. and i start by checking if the 30 seconds have passed, so the code in that if statement is the only code executed. This code has worked in previous builds (that are otherwise very outdated) but they were made in older versions of unity, so i don't know if that is the reason. It's just so specific, and i can't see why it would work after 5 seconds, but not 30 seconds. The only thing i can think of is using Time.deltaTime, but i don't see how that would work, since checking what the in game time is with Time.time should work (and has worked). I really hope you can help, cause i want this game released.

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 davidcox70 · Aug 05, 2020 at 11:29 PM 0
Share

Do you have value set in the editor for narrowTime, movingTime etc? These will overrule the ones in the script so it could be there are wrong numbers there. Time.time() is the correct one to use as it is the time in seconds since the game started.

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

132 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

Related Questions

Delay Player From Using Action Button For A Period Of Time 0 Answers

Changing light intensity over time via mathf.lerp 2 Answers

regenerating stats in update(); 1 Answer

After scene reload script stopped working. 1 Answer

Time.time stops working after reloading a level 4 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