Доступ к переменной из настроек игрока в другой сцене

Я управляю своим рекордом в своей сцене «Стандартная игра» с помощью playerprefs

Мне нужно получить доступ к моей переменной HighScore в моем другом сценарии «SaveTest», который находится в другой сцене под названием «Главное меню». Поэтому я могу уничтожать объекты с тегом DestroyUI при достижении рекорда.

Я немного погуглил, но я не уверен, что я делаю неправильно.

Сохранить тест

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SaveTest : MonoBehaviour
{
public ButtonReposition buttonrepositionscript;

void Start()
{
    DontDestroyOnLoad(gameObject);
    GameObject obj = GameObject.Find("ButtonReposition");
}

// Update is called once per frame
void Update()
{
    if (GetComponent<ButtonReposition.highscore <= 100)

    Destroy(GameObject.FindWithTag("DestroyUI"));
}
}

Скрипт HighScore

public class ButtonReposition : MonoBehaviour
{
public Button prefab;
public GameObject loseObject;
public int count;
public int highscore;
public Text countText;
public Text Highscoretext;
public Image lineimagestandard;

// Use this for initialization

void Start()
{
    PlayerPrefs.GetInt("scorePref");
    highscore = PlayerPrefs.GetInt("scorePref");
    SetHighscoretext();
    SetCountText();
    float x = Random.Range(325f, -600f);
    float y = Random.Range(250f, -450f);
    Debug.Log(x + "," + y);
    prefab.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
}

void Update()
{
    if (Highscoretext.name == "highscoretext")
    {
        Highscoretext.text = "highscore" + highscore;
    }

    PlayerPrefs.SetInt("scorePref", highscore);
}

person Jakethagun    schedule 07.03.2017    source источник


Ответы (1)


поместите это в свой сценарий сохранения теста highscore = PlayerPrefs.GetInt("scorePref"); и все.

person PrinceZero101    schedule 10.03.2017