NightRacer

: Unity, : C#, : JetBrains Rider, : 2 weeks, : School, : 5 people

In this project I worked with 4 other students. We were placed in random groups of students, so we can work with other students we have not worked with. The time we had for this project was 2 weeks. We decided on base of a brainstorming session How the game was going to look. After we have decided what the game look was we started brainstorming in smaller groups on what we want in the project. Such as: How do we want to move the player?, How are we going to save the high-scores? After that we were going to assign tasks to each other. And we did give each other 2x a day updates because of the scrum methode.

What did I learn in this project?

I have learned how I can work with PlayerPrefs. I also learned how I can make a good GameManager.

What did I do in this project?

I got the following tasks: Building GameManager, High-score system, Game loop and UI components such as: Numbers, Lap time, Score and High-score.

Code snippets

GameManager

/// CheckPause will check if the game is paused
    /// So yes it will be put on hold
    /// If not it will not be put on hold
    private void CheckPause()
    {
        if (Input.GetKeyDown(KeyCode.Escape) && m_GameState != GameState.Lost)
        {
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;

            if (m_GameState == GameState.Paused)
            {
                // Interface show pause false
                SetGameState(GameState.Game);
                Cursor.lockState = CursorLockMode.Locked;
                Time.timeScale = 1f;
                Cursor.visible = false;
                Debug.Log("Game is Unpaused");
            }
            else if (m_GameState == GameState.Game)
            {
                // inter face show pause true
                SetGameState(GameState.Paused);
                Time.timeScale = 0f;
                Debug.Log("Game is Paused");
            }
        }
    }

    /// Will start the game with the timer and lapsdriven
    public void StartGame()
    {
        M_IsCountingDown = false;
        m_Timer.M_TimeStarted = true;
        m_LapsDriven++;
        m_Particle.Play();
    }

    /// Set the win.
    /// Time will be stopped and will be saved in the timesaver script
    /// Highscore will change if it has a new highscore
    public void SetWin()
    {
        m_Timer.M_TimeStarted = false;

        // TimeSaver
        TimeSaver.M_Instance.ChangeTimes();
        TimeSaver.M_Instance.M_TimeInt++;

        // Change highscore if the score is above that
        if (m_Highscore.M_HighScore == 0)
            m_Highscore.HighScoreChanger(Mathf.RoundToInt(m_Timer.M_Timer));
        else if (m_Timer.M_Timer < m_Highscore.M_HighScore)
            m_Highscore.HighScoreChanger(Mathf.RoundToInt(m_Timer.M_Timer));
        m_Timer.M_Timer = 0;
        StartGame();

    }

HighScore

public class HighscoreSystem : MonoBehaviour
{
    public static HighscoreSystem M_Instance;

    [Header("Timer system")]
    public int M_HighScore;

    #region Singleton
    private void Awake()
    {
        if (M_Instance != null)
            Destroy(gameObject);
        else
            M_Instance = this;
    }
    #endregion

    private void Start()
    {
        // Displays the highscore on the screen
        M_HighScore = PlayerPrefs.GetInt("HighScore");
    }


    //change the highscore when is called upon
    public void HighScoreChanger(int _Time)
    {
        M_HighScore = _Time;

        AudioManger.M_Instance.PLay("NewHighScore");
        //changes the highscore player prefs
        PlayerPrefs.SetInt("HighScore", M_HighScore);
        PlayerPrefs.Save();
        Debug.Log(M_HighScore);
    }

All the code from this project:
Github Code