0

I have a game and I am doing now the UI (GUI) for that game to set some parameters. One of this parameter should be the duration of this game (in minutes). How can I define that when I type for example 3 in the input field , that the game should run 3 minutes?

Thank you for your help!

Edit:

Here the code I have so far:

public void DurationGame() { 

    float myTimer = 5.0f; 

    if (myTimer > 0) {
        myTimer -= Time.deltaTime;
    }

    if (myTimer <= 0) {

        //Game should stop here

        Debug.Log ("GAME OVER"); 
    }
sportente
  • 61
  • 1
  • 2
  • 8
  • Possible duplicate of [How do you add a timer to a C# console application](http://stackoverflow.com/questions/186084/how-do-you-add-a-timer-to-a-c-sharp-console-application) – Trevor Clarke Mar 24 '16 at 17:27
  • Numerous ways to implement this. Without seeing what you've tried already in your game code, it's difficult to advise on this. – ManoDestra Mar 24 '16 at 17:37
  • I do not a code so far because I do not know to do it at all. I have all the scripts for the game and that's it. Now I am working to do a GUI ... Please some help. – sportente Mar 24 '16 at 18:12
  • Read about local and class variables. I guess also your method is called once which means your hole code is executed once. – Felix K. Mar 25 '16 at 10:32

1 Answers1

1

You got it, just put that code in the Update function, like this:

public float myTimer = 5.0f;
public bool gameIsRunning; //you don't want to let the timer run while in pause

void Update ()
{
    if (myTimer > 0 && gameIsRunning) myTimer -= Time.deltaTime;
    else if (myTimer <= 0 && gameIsRunning) Debug.Log ("GAME OVER");
}
cortvi
  • 133
  • 10
  • Great thank you for your help. Do you have maybe also a suggestion for me for my other question I asked yesterday? Concerning the storage of the variables per player. I have another inputfield named SubjectID, I would like to have all variables per subject together for then analyzing then. Thank yo very much! – sportente Apr 02 '16 at 12:44
  • sry can you link me the question? :P – cortvi Apr 02 '16 at 16:16
  • Here is the link: http://stackoverflow.com/questions/36360745/how-to-save-variables-from-a-game-in-a-folder/36360872?noredirect=1#comment60341684_36360872 – sportente Apr 02 '16 at 17:20