Creating a Timer
Timers have a couple of big advantages over the yield statements. They will not delay code like a yield and they can be canceled. A yield cannot be stopped once the line has been read. The downside of a timer is that, unlike the single yield line, a timer takes a bit of coding. Using time to control events is used in all different kinds of genres, so it will be well worth the effort.
To start, you will need a couple of variables. The first will tell the engine if it even needs to check the time. A simple Boolean check for true or false will use fewer resources than fetching the time and comparing it with another float value. The check goes in the Update function, so it checked every frame.
1. Open the Interactor script. Add a couple of variables for the timer: