Over the past week, I’ve been creating the Time Attack mode and some other UI Elements for the pause menu.
This is the script for the first level in time attack. I’m sure that I only need one script for this which would work with every level but I created multiple as it was just easier to do. So those scripts look the same as this just with a few variables changed.
public float timer;
public float bestTime;
private bool timerOn;
public TMP_Text timerText, bestTimeText, endText;
public CharacterController charController;
public GameManager gameManager;
void Start()
{
gameManager._puzzleComplete = false;
charController.enabled = true;
timerOn = true;
bestTime = PlayerPrefs.GetFloat("Area 1 Best Time", 999);
bestTimeText.text = "Best Time: " + bestTime.ToString();
}
void Update()
{
if (timerOn)
{
timer += Time.deltaTime;
}
timerText.text = timer.ToString();
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
StartCoroutine(WaitLoad());
}
}
IEnumerator WaitLoad()
{
if (timer < bestTime)
{
PlayerPrefs.SetFloat("Area 1 Best Time", timer);
//bestTime = PlayerPrefs.GetFloat("Area 1 Best Time");
bestTimeText.text = "Best Time: " + timer.ToString();
}
timerOn = false;
endText.enabled = true;
charController.enabled = false;
yield return new WaitForSeconds(5f);
Cursor.lockState = CursorLockMode.None;
SceneManager.LoadScene("MainMenu");
}
This is the time attack menu. It displays the area location and the player’s best time once you beat the stage.
These lines are in the start function on the main menu script which sets the player’s best time for each stage at 999 so once the player beats a level it will then update to the new best time.
This is a checkerboard pattern that I quickly made in Photoshop for the end-of-the-time attack.
Here is a video that demonstrates the Time Attack Mode as well as the Brightness Slider in action.
11th May
I created some new UI for the Pause Menu sliders and buttons as previously they were the default Unity ones. These are the new art for the slider components.
This is what the pause menu now looks like.