Search Unity

My script is working only once. How can I make it works evertime. Gameobject is button

Discussion in 'Scripting' started by Lupinder, Mar 21, 2020.

  1. Lupinder

    Lupinder

    Joined:
    Oct 6, 2018
    Posts:
    64
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4.  
    5.  
    6. public class Cooldown : MonoBehaviour
    7. {
    8.  
    9.  
    10.     float timer = 0;
    11.  
    12.     public GameObject Enable_Disable;
    13.  
    14.  
    15.    
    16.     public void Enable()
    17.     {
    18.  
    19.         Enable_Disable.SetActive(true);
    20.  
    21.  
    22.     }
    23.  
    24.  
    25.     public void Disable()
    26.  
    27.     {
    28.         Enable_Disable.SetActive(false);
    29.  
    30.     }
    31.  
    32.  
    33.     void Update()
    34.     {
    35.  
    36.  
    37.         timer = timer + Time.deltaTime;
    38.  
    39.         if (timer > 6)
    40.         {
    41.             Enable_Disable.SetActive(true);
    42.          
    43.  
    44.         }
    45.     }
    46.  
    47.  
    48. }
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    10,331
    After calling Enable_Disable.SetActive, reset timer value.
     
  3. Lupinder

    Lupinder

    Joined:
    Oct 6, 2018
    Posts:
    64
    Thanks for help . it worked
     
    Last edited: Mar 21, 2020
unityunity