> For the complete documentation index, see [llms.txt](https://kdoore.gitbook.io/cs2335/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kdoore.gitbook.io/cs2335/mini-game_proj4/simplified-mini-game/minigamemanagerv2.md).

# MiniGameManager\_v2

This code is used with the simplified MiniGame\_v2, provided to students who didn't complete a working version of the MiniGame in Project 1, so they can complete a working version of Project 3.

```java
using UnityEngine;
using UnityEngine.UI;

public enum MiniGame_v2State { idle, active, win, lose }

public class MiniGameManager_v2 : MonoBehaviour
{
    public MiniGame_v2State curGameState = MiniGame_v2State.idle;
    public Button startButton; //set in inspector
    public int winScore = 30;
    public GameObject pickUp_Parent;

    // Use this for initialization
    void Start()
    {
        startButton.onClick.AddListener(StartGame);
        StartGame(); //calls method with StartGame Logic
        //StartGame() disables startButton, so enable it at start
        startButton.gameObject.SetActive(true); //displays the StartButton 
    }

    // Update is called once per frame
    void Update()
    {
        if (curGameState == MiniGame_v2State.active)
        {
            if (GameData.instanceRef.Health > 0) //still have health
            {
                if( GameData.instanceRef.Score >= winScore)
                {
                    curGameState = MiniGame_v2State.win;

                    GameOver();
                }
            }
            else //we have no health
            {
                curGameState = MiniGame_v2State.lose;

                GameOver();
            }
        }
    } //end update

    private void GameOver()
    {
        startButton.gameObject.SetActive(true); //set gameObject with Button Component to active
    }

    /// <summary>
    /// starts game.
    /// Executed by Unity when the StartButton is clicked
    /// </summary>
    public void StartGame()
    {
        GameData.instanceRef.ResetGameData();
        pickUp_Parent.SetActive(true);
        curGameState = MiniGame_v2State.active; //FSM - change state
        startButton.gameObject.SetActive(false); //disables the StartButton GO
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kdoore.gitbook.io/cs2335/mini-game_proj4/simplified-mini-game/minigamemanagerv2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
