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 Wendek · Oct 29, 2013 at 04:01 PM · timers

How to create a UDK-like timer to call a function ?

Hello,

I've started using Unity recently and I'm trying to "find my marks" after working on UDK for 6 months. One very useful function of UDK is a timer : basically it allows you to call a function after a specific amount of time has elapsed. Is there anything similar to this in Unity ? I've seen a few threads but they all seem to involve tinkering with the Update() function. I'm talking about something really simple which is called like this : "SetTimer(time, repeat, nameOfFunction). Repeat basically means whether it has to be called once or if it should be called again after each call. (say, you wanted to call a function every second for the duration of the program)

In my case, I want to use it (among other things) for an "AttackSpeed" statistic for my unit : the unit should attack its target X times per second, where X is its attack speed (so if it has an attackspeed of 1, then it attacks once per second, twice with an AS of 2, etc).

Thanks in advance for your help. (Also I hope that referencing other engines is not prohibited here because that's really the easiest way for me to give a reference to what I mean)

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

Answer by Dave-Carlile · Oct 29, 2013 at 04:01 PM

You can use the Invoke function to do this. It accepts a timer value and will call the function after that amount of time.

There is also InvokeRepeating, which will invoke the function repeatedly at your specified interval.

Comment
Add comment · Show 3 · 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 Wendek · Oct 29, 2013 at 04:04 PM 0
Share

This is exactly what I was looking for. Thanks a lot.

avatar image RowedRage0 · Oct 29, 2013 at 04:08 PM 0
Share

Dave, thanks for the response. FYI that first link is broken. Should be Invoke.

avatar image Dave-Carlile · Oct 29, 2013 at 04:22 PM 0
Share

heh - thanks for the notice. Guess Ctrl+C didn't work and you got the last link I copied. Fortunately it wasn't anything embarassing.

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

17 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

Related Questions

Problem with Time.time 0 Answers

How to make a stopwatch that restarts every time the player dies and saves it as a highscore 3 Answers

Are there any performance differences between a timer and using Invoke? 1 Answer

Trying to get Timed button presses within a timed window 1 Answer

Timer Data Across Scene Changes 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