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

7z and D

After sometime manually creating zip files and manually moving the files to the appropriate folder for sometime, I just realised that 7zip has it’s own command line interface. Yay! Windows did not provide a command line interface for the... Continue →