Question by 
               hallonkatastrof · Oct 12, 2016 at 10:28 PM · 
                c#buttoncooldown  
              
 
              C# cool down not looping
I've made a 5 second cool down function starting upon button click. It doesn't loop though, only works once. What's wrong?
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class button1 : MonoBehaviour {
 
     public bool startTimer = false;
     public bool ready = true;
     int counter = 0;
     public int coolDown = 5;
     public float Counter = 0f;
     public Image buttonImage;
 
     // Update is called once per frame
     public void Clicked()
     { 
         if (ready == true) {
             counter = counter + 1;
             Debug.Log ("Button1: Clicked");
             buttonImage.fillAmount -= coolDown * Time.time;
             ready = false;
             startTimer = true;
         }
     }
         void Update ()
         {
         if (startTimer == true) 
         {
             Counter = Time.time;
         }
         if (Counter >= coolDown) 
         {
             ready = true;
             startTimer = false;
             Counter = 0f;
             buttonImage.fillAmount += coolDown * Time.time;
         }
         }
 }
 
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
OnClick() event script from a prefab 0 Answers
Referencing a button in script for different game modes in the Space Shooter Tutorial 0 Answers
LoadScene not Working 1 Answer
Pick your path text adventure 0 Answers
How to make ui only activate once 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                