Time: 13 march 2023 - 7 april 2023
Rollover is a game about you being miltible marbles. you control then in sequence. Experience multible levels and explore from platformer to an advanture.
The "FinishRequirements" script checks for level completion by confirming that all marbles are on buttons. If successful, it marks the level as complete, updates personal best times, and returns players to the lobby.
Within the lobby, the "LobbyManager" script identifies completed levels and unlocks them for access. It also showcases personal best times, encouraging players to strive for improvement.
These scripts enrich our game by recognizing player achievements and progress, fostering a more engaging gaming experience. Players can track their best times, aim to conquer all levels, and relish their accomplishments. see code beneath.
using UnityEngine;
using UnityEngine.SceneManagement;
public class FinishRequirements : MonoBehaviour
{
[SerializeField] private CheckingButton[] _buttons;
[SerializeField] private LevelManager data;
[SerializeField] private GameManager _gameManager;
private void Awake()
{
_gameManager = FindObjectOfType<GameManager>();
}
private void Update()
{
SendPlayerBackToLobby();
}
private bool AreAllMarblesOnButtons()
{
bool allActive = true;
foreach (CheckingButton button in _buttons)
{
if (button.playerIsOnButton == false)
{
allActive = false;
break;
}
}
return allActive;
}
private void SendPlayerBackToLobby()
{
if (AreAllMarblesOnButtons())
{
data.CompletedLevel[SceneManager.GetActiveScene().buildIndex - 1] = true;
SettingPersonalBest();
SceneManager.LoadScene("lobby");
}
}
private void SettingPersonalBest()
{
if (data.levelPersonalBest[SceneManager.GetActiveScene().buildIndex - 2] == -1)
{
data.levelPersonalBest[SceneManager.GetActiveScene().buildIndex - 2] = _gameManager.levelTimer;
}
else if (data.levelPersonalBest[SceneManager.GetActiveScene().buildIndex - 2] > _gameManager.levelTimer)
{
data.levelPersonalBest[SceneManager.GetActiveScene().buildIndex - 2] = _gameManager.levelTimer;
}
}
}
using System;
using TMPro;
using UnityEngine;
public class LobbyManager : MonoBehaviour
{
[SerializeField] private GameObject[] levelLocked;
[SerializeField] private LevelManager _leveldata;
[SerializeField] private TextMeshProUGUI[] personalBestDisplay;
private void Start()
{
CheckingLockStatus();
ReplacingPersonalBest();
}
private void CheckingLockStatus()
{
for (int i = 0; i < _leveldata.CompletedLevel.Length; i++)
{
if (_leveldata.CompletedLevel[i])
{
levelLocked[i].SetActive(false);
}
}
}
private void ReplacingPersonalBest()
{
for (int i = 0; i < Math.Min(_leveldata.levelPersonalBest.Length, personalBestDisplay.Length); i++)
{
personalBestDisplay[i].text = _leveldata.levelPersonalBest[i] == -1
? "No Record yet"
: GameManager.FormatTime(_leveldata.levelPersonalBest[i]);
}
}
}
using UnityEngine;
public class GameManager : MonoBehaviour
{
#region TimeSystem
public static string FormatTime(float time)
{
int minutes = Mathf.FloorToInt(time / 60);
float seconds = time % 60f;
seconds = Mathf.Round(seconds * 100f) / 100f; // round to two decimal places
return string.Format("{0:00}:{1:00.00}", minutes, seconds);
}
#endregion
}