{"id":1104,"date":"2022-03-07T21:03:18","date_gmt":"2022-03-07T21:03:18","guid":{"rendered":"https:\/\/golemitegames.com\/?post_type=docs&#038;p=1104"},"modified":"2022-07-27T16:31:44","modified_gmt":"2022-07-27T16:31:44","password":"","slug":"scripting","status":"publish","type":"docs","link":"https:\/\/golemitegames.com\/index.php\/docs\/scripting\/","title":{"rendered":"Scripting"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" style=\"font-size:22px;text-transform:capitalize\">Public methods<\/h2>\n\n\n\n<p>There are several public methods that can be called from the Timer script.<\/p>\n\n\n\n<p>First of all, make sure to get a reference to the Timer class in your preferred method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">double GetRemainingSeconds()<\/h2>\n\n\n\n<p>This will return the number of remaining seconds. For example, you can make a check every second to see if the remaining time is equal to halfway through.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Console logs the remaining seconds\ndouble secondsLeft = myTimer.GetRemainingSeconds();\nDebug.Log(secondsLeft);<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">StartTimer()<\/h2>\n\n\n\n<p>This method simply starts the timer, with the time set in the inspector. You have to stop the timer or wait for it to end before calling this method again.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Starts the timer after 5 seconds\nmyTimer.Invoke(&quot;StartTimer&quot;, 5f);<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">StopTimer()<\/h2>\n\n\n\n<p>This will stop the timer from running, and reset its values according to the count method. If counting up, your reset value will be 0, if counting down, your reset value will be the values set in Set time.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Stops the timer if there is less than 5 seconds remaining\n\/\/Checks every 0.25 of a second.\nvoid Start() \n{\n    InvokeRepeating(&quot;CheckTimer&quot;, 0, 0.25f)\n}\nprivate void CheckTimer() \n{\n    if(myTimer.GetRemainingSeconds() &lt; 5) \n    {\n        myTimer.StopTimer();\n    }\n}\n\n\/\/Results in the timer being stopped and reset to the time set in the inspector\n<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">PauseTimer()<\/h2>\n\n\n\n<p>Pauses the timer, stopping all counting without resetting anything. If the timer is paused, you can either resume or stop the timer. Please note you cannot start a new timer while it is paused.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Pauses the timer if key &quot;p&quot; is pressed\nvoid Update()\n{\n    if(Input.GetKeyDown(&quot;p&quot;))\n    {\n        PauseTimer();\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p><strong>Note<\/strong> &#8211; This is a paid feature.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">ResumeTimer()<\/h2>\n\n\n\n<p>Resumes the timer if it was paused. This method only works if the timer is paused.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Resumes the timer if key &quot;r&quot; is pressed\nvoid Update()\n{\n    if(Input.GetKeyDown(&quot;r&quot;))\n    {\n        ResumeTimer();\n    }\n}\n<\/code><\/pre><\/div>\n\n\n\n<p><strong>Note<\/strong> &#8211; This is a paid feature.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">AddTime(float seconds)<\/h2>\n\n\n\n<p>Add time to the timer in seconds. You can use the inspector Set time section to work out how many seconds to add. This will only work if the time to add will not take you beyond the Set time if counting down. Please note, this method by its nature works in reverse when you change the count method. For example, trying to add time to a timer counting down from 10 seconds, will make the timer last longer. When adding time to counting up, it will make the timer end quicker.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Adds more time if the level has been won. \nbool levelWin = false;\nint score = 0;\nvoid Update()\n{\n    if(score &gt;= 40) \n    {\n        levelWin = true;\n        score = 0;\n    }\n    if(levelWin)\n    {\n        AddTime(60);\n        levelWin = false;\n    }   \n}\nvoid addScore() \n{\n    score++;\n}<\/code><\/pre><\/div>\n\n\n\n<p><strong>Note<\/strong> &#8211; This is a paid feature.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">RemoveTime(float seconds)<\/h2>\n\n\n\n<p>Resumes the timer if it was paused. This method only works if the timer is paused.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Removes time if you lose the level.\nbool levelWin = false;\nint score = 0;\nvoid Update()\n{\n    if(score &lt; 40) \n    {\n        levelWin = true;\n        score = 0;\n    }\n    if(levelWin)\n    {\n        RemoveTime(30);\n    }   \n}\nvoid addScore() \n{\n    score++;\n}\n<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">float ReturnTotalSeconds()<\/h2>\n\n\n\n<p>This will return the number of seconds set in the inspector under Set time. This does not count, it simply returns the total number of seconds set.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/If the timers current seconds left are less than the seconds set in the inspector.\nif(ReturnTotalSeconds() &gt; GetRemainingSeconds()) \n{\n    Debug.Log(&quot;Timer has started&quot;);\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>double ConvertToTotalSeconds(float days, float hours, float minutes, float seconds)<\/strong><\/h2>\n\n\n\n<p>You can call this function with your desired days, hours, minutes and seconds to receive these values returned as seconds.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Displays 1 day, 14 hours, 10 minutes and 37 seconds in seconds. \ndouble seconds = ConvertToTotalSeconds(1, 14, 10, 37);\nDebug.Log(seconds);\n<\/code><\/pre><\/div>\n\n\n\n<p><strong>Note<\/strong> &#8211; For the free version, you can call this function without the days parameter. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>string DisplayFormattedTime(double remainingSeconds)<\/strong><\/h2>\n\n\n\n<p>This method handles the display input and output. If you put a total number of seconds into it, it will convert it and return a string of the selected display options set in the inspector. This method is used in conjunction with the remaining seconds to output the remaining time in a text format.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Displays a string of your remaining time using the display options set in the inspector. \nstring timeLeft = DisplayFormattedTime(GetRemainingSeconds());\nDebug.Log(timeLeft);\n<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Public methods There are several public methods that can be called from the Timer script. First of all, make sure to get a reference to the Timer class in your preferred method. double GetRemainingSeconds() This will return the number of remaining seconds. For example, you can make a check every second to see if the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"doc_category":[14],"doc_tag":[],"class_list":["post-1104","docs","type-docs","status-publish","hentry","doc_category-timersmadeeasy"],"acf":[],"aioseo_notices":[],"year_month":"2026-04","word_count":675,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"rickitz5h","author_nicename":"rickitz5h","author_url":"https:\/\/golemitegames.com\/index.php\/author\/rickitz5h\/"},"doc_category_info":[{"term_name":"Timers Made Easy","term_url":"https:\/\/golemitegames.com\/index.php\/docs-category\/timersmadeeasy\/"}],"doc_tag_info":[],"_links":{"self":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/comments?post=1104"}],"version-history":[{"count":32,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1104\/revisions"}],"predecessor-version":[{"id":1732,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1104\/revisions\/1732"}],"wp:attachment":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/media?parent=1104"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_category?post=1104"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_tag?post=1104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}