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 zeuo · Mar 28, 2012 at 03:46 AM · buttontimercooldownskills

how to make a button click able after a few seconds

every rpg game has skills and when u click on them then there is a cooldown time where you cant click on the button again im trying to make that in unity but its not working i dont want to use WaitForSeconds becuase that dosent work if i use that then the button wount show up any help plizz

Comment
Add comment · Show 3
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 AlucardJay · Mar 28, 2012 at 04:10 AM 0
Share

Here is an answer I wrote for a similar case - but it does exactly what you want. It uses WaitForSeconds in a co-routine and a boolean to toggle the button being displayed or not :

Answer : http://answers.unity3d.com/questions/231521/how-to-display-data-in-an-array.html

Example : http://www.alucardj.net16.net/unityanswers/hintbutton1-1.html

avatar image venkspower · Mar 28, 2012 at 04:24 AM 0
Share

A normal counter would do the business, I believe.

avatar image syclamoth · Mar 28, 2012 at 05:00 AM 0
Share

There's abosolutely nothing stopping WaitForSeconds from working in this situation. Just think about it more, it's pretty obvious what you have to do.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by AlucardJay · Mar 28, 2012 at 05:07 AM

Here's a solution using a counter :

 var myCounter : float = 0.0;
 var mySetTime : float = 2.5;
 
 function OnGUI () {
     // when my set time is reached
     if (myCounter >= mySetTime) {
         // show GUI Button
         if (GUI.Button(Rect(10, 10, 100, 35), "Start Again")) {
             myCounter = 0.0;
         }
     }
     // add time to counter
     // use myCounter++; (same as myCounter+=1;) to count the frames - or
     myCounter += Time.deltaTime; // 
     
     // display counter
     GUI.TextField (Rect((Screen.width/2)-100, 10, 200, 25), "myCounter : " + myCounter);
     GUI.TextField (Rect((Screen.width/2)-100, 40, 200, 25), "mySetTime : " + mySetTime + "secs");
 }
Comment
Add comment · Show 2 · 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 primus88 · May 25, 2013 at 04:29 PM 0
Share

Can someone please help me ? I used this script and indeed works flawlessly, but I need it to trigger the cooldown by using keys from the keyboard and not mouse click.

Any ideas ?

avatar image ESCPE · Nov 11, 2013 at 02:36 PM 0
Share
 if(input.Get$$anonymous$$ey($$anonymous$$eyCode.A) {
  if (GUI.Button(Rect(10, 10, 100, 35), "Start Again")) {
          myCounter = 0.0;
        }
 }

$$anonymous$$aybe? Im not good at this but you can test :)

avatar image
0

Answer by static_cast · Nov 11, 2013 at 03:13 PM

Here is some psuedocode because I don't have much experience with GUIButtons that might work:

 var buttonClicked = false;
 
 function OnButtonClick() //DON'T KNOW IF THIS FUNCTION EXISTS
  {
  if(buttonClicked == false)
   {
   buttonClicked = true;
   //CARRY OUT BUTTON STUFFS HERE
   yield WaitForSeconds(1.0); //CHANGE THIS TO THE NUMBER OF SECONDS YOU WANT TO WAIT FOR
   buttonClicked = false;
   }
  }
Comment
Add comment · 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

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

10 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

Related Questions

GUI & GUI Text Disappear When Publishing 6 Answers

Why my button in for loop isn't working? 1 Answer

Deactivating a power up script after a certain amount of time 1 Answer

Usage timer/weapon cooldown... 3 Answers

Very Very Precise Timer ? 0 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