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 Borr1310 · Oct 24, 2016 at 07:01 PM · timespawningif-statementsstartinvokerepeating

if and invoke repeating in start...

This is my obstacle spawning code:

 public GameObject Obstacles;
         float gameTime;
        
         
         void Start()
         {
             gameTime = Time.timeSinceLevelLoad;
             InvokeRepeating("CreateObstacle", 1f, 1.25f);
         }
         void Update()
         {  
         }
         
         void CreateObstacle()
         {  
             Instantiate(Obstacles);
         }

Now what I want to do is InvokeRepeat 1F, 1.25F only when gameTime > 0 && gameTime <= 46. And InvokeRepeat 0.25f, 0.85f when gameTime > 46.

I have no idea how to do this, beceause if I´d try to make couple if statements they would never update beceause they have to be called in Start() right?

Thanks!

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
0

Answer by hexagonius · Oct 24, 2016 at 07:32 PM

your assumption is correct, your if statement needs constant checking. What I'd do is check in update for a Boolean (above46seconds) and if true, return.
after that return statement check for the time and if it meets your condition. If it does, execute CancelInvoke, the ne InvokeRepeating and set the Boolean.
this way, when you go above 46 seconds, the invoke gets exchanged and update stops on the first if statement.
If you do all this with coroutines, there won't be any execution at all when finished.

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 Borr1310 · Oct 24, 2016 at 07:52 PM 0
Share

I am trying to get it working but I have some problems with the logic. If you could give me a code example it would be much easier, anyway thanks! @hexagonius

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Time hasn't stopped 1 Answer

Problem with countdown timer. 3 Answers

audio troubles changing from one to another (stop it consistently changing) 1 Answer

Spawning enemies based on array of times 0 Answers

i want tospawn objects 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