2017-03-07 4 views
1

でプレイヤーのprefsから変数へのアクセス別のシーンは "メインメニュー"と呼ばれるので、私は最高のスコアに達すると、DestroyUIタグのオブジェクトを破壊することができます。使用playerprefs</p>私は私の他のスクリプトである「SaveTest」で私の変数ハイスコアにアクセスする必要が <p>によって、私は私のシーン「標準ゲーム」で私のハイスコアを管理しています別のシーン

私はちょっとグーグルではありますが、何が間違っているのかわかりません。

保存テスト

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")); 
} 
} 

ハイスコアスクリプト

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); 
} 

答えて

2

は、あなたの保存テストスクリプトhighscore = PlayerPrefs.GetInt("scorePref"); でこれを入れて、それはそれです。

関連する問題