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 chronos2669 · Sep 04, 2020 at 06:07 PM · timerfloatattacktimed

Attack based on timer

I'm working on an attack system and wondering what the most efficient way of doing it would be. As the attack button is pressed, a counter is to start from 0.00, that goes up to 1.00, and then back down to 0.00. A UI bar shows the progress as it rises and falls, and if the attack button is pressed again during that progress, it stops and returns that float value. Any help appreciated, thanks :)

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 BenWiller1989 · Sep 05, 2020 at 12:29 AM 0
Share

So the easiest solution for it is to use a linear interpolation of a time value, counting from 0 to 2 sec or something : if (presentTimevalue <= 1f) { image. Fillamount = (1+((0-1)/(0-1))*(presentTimevalue-2));} if (presentTimevalue > 1f) { image. Fillamount = (0+((1-0)/(1-2))*(presentTimevalue-2));} that should do it!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BenWiller1989 · Sep 04, 2020 at 06:09 PM

If you use animations on it, you could use animation events for a perfect precision. But since I don't know, what type of game, its hard to say.

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 chronos2669 · Sep 04, 2020 at 11:20 PM 0
Share

I just really need to know how I can start a counter that goes up to 1 and then back to 0, the rest I can do on my own - any ideas?

avatar image BenWiller1989 chronos2669 · Sep 04, 2020 at 11:28 PM 0
Share

Y... Yes..., make a coroutine if you need seconds, since one second $$anonymous$$us one makes counted two,... So yield return new waitforseconds(1f) ; I don't know, why you need one and back but wathever you need. What counter do you mean? 1 to 10, every second or variable, every millisecond? That would be nice to know. Do you know how coroutine work?

avatar image chronos2669 BenWiller1989 · Sep 04, 2020 at 11:43 PM 0
Share

yeah I know the basics of coroutines, not much though - since it's tied to the visual of a bar filling up and then depleting I thought it'd be better if it went from 0, to 1, then to 0 again. I'm using a UI image to display the bar on-screen, and the "fill" float value goes from 0 to 1

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

136 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

Related Questions

Attack speed 1 Answer

Cannot convert 'String' to 'float (but im actualy converting a float to a string) 2 Answers

Timer variable set to zero 2 Answers

cant change variable from a method? timer stays at 0! 1 Answer

Start timer with trigger 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