Сохранение значения переменной
Добавлено: 21 окт 2018, 13:32
Есть скрипт для набора очков и вывода этих очков на экран, так же в скрипте есть переменная с рекордом (HighScore) и мне значение этой переменной надо сохранить, как это можно сделать? Подскажите пожалуйста
Вот скрипт
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public int Score_Character;
private float Scoree;
private float HighScore;
public Text txt;
public Text yourscore;
public Text bestscore;
private float timer;
// Use this for initialization
void Start()
{
Score_Character = PlayerPrefs.GetInt("Score", Score_Character);
}
// Update is called once per frame
void Update()
{
PlayerPrefs.SetInt("Score", Score_Character);
txt.text = "" + Score_Character;
if (!Character.lose)
{
HighScore = 0;
timer += 1 * Time.deltaTime;
if (timer > 1)
{
Score_Character += 1;
timer = 0;
}
yourscore.text = "";
bestscore.text = "";
Scoree = Score_Character;
}
if (Character.lose)
{
Score_Character = 0;
txt.text = "";
yourscore.text = Scoree + " " + "POINTS";
if (Scoree > HighScore)
{
HighScore = Scoree;
}
bestscore.text = "BEST SCORE:" + " " + HighScore;
}
}
}
Вот скрипт
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public int Score_Character;
private float Scoree;
private float HighScore;
public Text txt;
public Text yourscore;
public Text bestscore;
private float timer;
// Use this for initialization
void Start()
{
Score_Character = PlayerPrefs.GetInt("Score", Score_Character);
}
// Update is called once per frame
void Update()
{
PlayerPrefs.SetInt("Score", Score_Character);
txt.text = "" + Score_Character;
if (!Character.lose)
{
HighScore = 0;
timer += 1 * Time.deltaTime;
if (timer > 1)
{
Score_Character += 1;
timer = 0;
}
yourscore.text = "";
bestscore.text = "";
Scoree = Score_Character;
}
if (Character.lose)
{
Score_Character = 0;
txt.text = "";
yourscore.text = Scoree + " " + "POINTS";
if (Scoree > HighScore)
{
HighScore = Scoree;
}
bestscore.text = "BEST SCORE:" + " " + HighScore;
}
}
}