Search Unity

Question countdown timer for different areas

Discussion in 'Visual Scripting' started by engMohAmr, May 8, 2023.

  1. engMohAmr

    engMohAmr

    Joined:
    Feb 25, 2023
    Posts:
    3
    Hello everyone,

    I have a question how do I program the game by using a countdown timer for areas (A, B, and C) with different rates for each area? (Visual scripting is preferable)

    For example : Area A rate = 3 per second
    Area B rate = 1.5 per second,
    Area C rate = 1 per second
     
  2. TheNullReference

    TheNullReference

    Joined:
    Nov 30, 2018
    Posts:
    268
    Each area can be a BoxCollider2D that changes the Rate when OnTriggerEnter is called.
     
  3. engMohAmr

    engMohAmr

    Joined:
    Feb 25, 2023
    Posts:
    3
    Thank you for your response, but I'm beginner so if you show me complete flow will be better
     
  4. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    120
    There's a bunch of ways to do timers. I use while loops. Each zone would get a script and a script variable for timer and for max time.

    In this instance, Player enters the trigger collider and runs the timer. Then, it resets the timer on exit but you can remove that if you are just needing the timer to end. If you need to access the variable from another object/script, make it an object variable instead of graph variable.

    *Note on the while loop, if you disconnect the wait for seconds it will lock up your game. So, don't do that. The while loop is the most efficient method to run VS so it's good to learn how to use it with events. Save your game before you ever run a while loop if you aren't comfortable with them. heh.

    upload_2023-5-8_9-50-12.png