using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using System.IO;
using TMPro;
using System;
using UnityEngine.TextCore.Text;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Menu : MonoBehaviour
{
public TextMeshProUGUI HightScore;
private float HightScoreValue;
// Update is called once per frame
void Update()
{
//vareables
string path = Path.Combine(Application.dataPath, "../Data/hightScore.txt");
//try catch structure to check if the files have been temperd with or curupted
try
{
//checking if the file exsists
if (File.Exists(path))
{
//checking if the file is in the correct format
string[] lines = File.ReadAllLines(path);
if (lines.Length == 1)
{
//checking if the recorded value is a number
HightScoreValue = float.Parse(lines[0]);
//displaying the high score value
HightScore.text = "Hight Score : " + HightScoreValue;
}
else
{
//throwing an error if the file is not in the correct format
throw new Exception("to many lines");
}
}
else
{
Debug.LogError("File not found: " + path);
}
}
catch
{
//Erasing the high score data
File.WriteAllText(path, String.Empty);
}
}
///
/// To run when the player clicks the start or restart buttonsbutton, and changing the scene
/// to the game scene (the scene that the game is played in)
///
public void StartGame()
{
//Loading the game scene
SceneManager.LoadScene("SampleScene");
}
///
/// To run when the quit game button is pressed, and quiting the applecation
///
public void ExitGame()
{
// quit/close the game
Application.Quit();
}
}