Tick Tock

Time is an important concept in games, controlling and constraining player actions so we could have a better game structure.

From time to time, I had implemented a timer like this:

    class timer:
        public start=false
        public time=Time.time

        def Start ():
            record = timer()

        def Update ():
            if state["shoot"]==true:
                if record.start == false: 
                BL=GameObject.Instatiate(bullet, self.transform.position, self.transform.rotation) as GameObject
                record.time=Time.time
                record.start=true
            else:
                if (Time.time-record.time)>cooltime :
                    record.start=false
                    record.time=Time.time
                    state["shoot"]=false

This timer was the original implementation of a custom cooldown clock, but this code is messy and violates the DRY principle, so there has to be a better way to do it.

I took inspiration from the minimalist design of GUI buttons in Unity3D. The buttons return true if clicked, and false if not. So I went and create my own custom timer that would be imported whenever needed, based on that concept.

It returned true whenever the timer could be started and false whenever it was not! Of course, the timer could be customized further if required, but there was not a need yet.

Oh the joys of solving problems.

 
0
Kudos
 
0
Kudos

Now read this

Audio controllers

Apparently the best way to control background music (BGM) and sound effects (SFX) was to create global booleans to be checked to play sounds. I reverted the original change from using the AudioListener.PlayClipAtPoint() static function... Continue →