Question by
AlanG97 · Apr 04, 2016 at 03:43 PM ·
c#timeloadingscoreboard
Load score
I have created a fastest time table and i have written a script with saves the current fastest times to a .txt file. I have then written this code to then be able to load that file and put the saved times back on the board but when i click the button to activate it the code doesnt seem to work? Can anyone please help me.
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Collections.Generic;
public class LoadScore : MonoBehaviour
{
public GameObject Firstt;
public GameObject Secondd;
public GameObject Thirdd;
public Color magic;
void OnMouseEnter()
{
GetComponent<TextMesh> ().color = Color.red;
}
void OnMouseExit()
{
GetComponent<TextMesh> ().color = Color.white;
}
void OnMouseOver()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
string readtext = File.ReadAllText(Application.dataPath + "/RunHighscores.txt");
string first = readtext.Substring (8,3);
string second = readtext.Substring (22,3);
string third = readtext.Substring (35,3);
int First = int.Parse(first);
int Second = int.Parse (second);
int Third = int.Parse (third);
PlayerPrefs.SetInt ("First", First);
PlayerPrefs.SetInt ("Second", Second);
PlayerPrefs.SetInt ("Third", Third);
Firstt.GetComponent<TextMesh>().text= "1ST PLACE - " + First;
Secondd.GetComponent<TextMesh>().text= "2ND PLACE - " + Second;
Thirdd.GetComponent<TextMesh>().text= "3RD PLACE - " + Third;
}
}
}
Comment