- Home /
Scoring System/Clock?
Hello, I have two simple questions 1: How do I set a timer and activate a script when the timer reaches a certain value? 2: How do I add a simple scoring system (when ever thing A happens, Increase Score by X value and register on the GUI)? Thanks
Your second question should be put separately, it has nothing to do with your first question or title.
Answer by denewbie · Nov 06, 2010 at 05:00 PM
Try this:
var myScore = 0; var DelayTime = 10; // 10 seconds before activating function
function Start(){ Invoke("myFunction", DelayTime); }
function OnGUI(){ GUI.Label(Rect(0,0, 200, 30), "Score: " + myScore); }
function SomethingAppears(){ myScore++; }
Answer by Herman-Tulleken · Nov 05, 2010 at 06:12 AM
For timed events, use Invoke:
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Invoke.html
Answer by Gian Hancock · Nov 05, 2010 at 10:15 AM
Herman Tulleken has already answered your first question so i wont worry about that. As for your second question i would set a static variable that stores the score value.
I am not sure on the exact details on your game but something like this should work
//put this script in the object that calls the point scoring event var pointAmount : float = 10;
//put this somewhere in the script so that it only runs when the point scoring event occurs score += pointAmount;
Just make sure that a static "score" is declared and set the HUD to draw the value of score.
Answer by Lab013 · Mar 17, 2011 at 03:41 AM
Te Tme class offers a lot of functionality relating to time...
Your answer
![](https://koobas.hobune.stream/wayback/20220613082032im_/https://answers.unity.com/themes/thub/images/avi.jpg)