Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Waiting in Update()

Discussion in 'Testing & Automation' started by sakite121, Apr 17, 2022.

  1. sakite121

    sakite121

    Joined:
    Apr 17, 2022
    Posts:
    5
    So i am trying to make a clicker game with Autoclicker. But there is a Problem i use changing Score in Update() like this

    public int Score;
    public int ChangebyClick;
    public Text Scoretext;
    public GameObject ShopUI;
    public static bool IsShopActive = false;
    public static bool AutoClicker = false;
    public int AutoClick;
    // Start is called before the first frame update
    void Start()
    {
    Score = 0;
    ChangebyClick = 10;
    }
    // Update is called once per frame
    void Update()
    {
    if (AutoClicker)
    {
    Score = Score + AutoClick;
    }
    Scoretext.text = Score.ToString("0");
    }
    public void ChangeScore()
    {
    Score = Score + ChangebyClick;
    Debug.Log(Score);
    }

    And so its just going relly fast, I mean in 3 seconds to 3000 Score
    But i cant put yield WaitForSeconds (3); after Score = Score + AutoClick;

    Please help me!

    Thanks!
     
  2. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    493
    Use Time.deltaTime to get the elapsed time since the last frame.
    On every update, add that to a counter and if that counter's value is > 3, reset it and do whatever you wanted to do after waiting.