Timer between two nodes

Hello. So in my world, I would like to add a timer between two nodes. For example, once the script is triggered, it plays an audio source for X amount of time, then switches it back off. Is this possible? And if so, how would I do it?

I’m assuming you just need it to turn itself off after X seconds of being turned on.
So assuming you have the audio source as a child of or alongside the udon script, all you need to do is have a script that;

-On update
-Add a custom float “elapsedTime” + Time.deltaTime (completion time in seconds since the last frame)
-Branch for: if elapsed time is greater than or equal to a custom public float timerTick (how many seconds to stay on for)
-If true, set elapsedTime to a constant float of 0
-Then GameObject.SetActive to false

Udon Graph:

U# Code:

//Instance Variables
private float _elapsedTime = 0;
public float timerTick = 1;

private void Update()
    _elapsedTime += Time.deltaTime;
    if (!(_elapsedTime >= timerTick)) return;
    _elapsedTime = 0;


Thank you! I’m going to try this now! (sry for late reply)

1 Like