2017-12-02 14 views
0

각 개별 게임 개체의 활성 상태를 저장하려고하므로 다시로드 할 때 수집 한 개체가 더 이상 존재하지 않게됩니다. 내 코드 : I 개별적으로 각각 확인 어떻게유니티 GameObject 플레이어 액티브로 SetActive 저장

public class PlayerController : MonoBehaviour { 

    public LevelManager levelManager;   
    public GameObject[] stardust; //array of stardust in level 
    public int isActive; //variable for amount of stardust collected 

    void Start() 
    {    
     isActive = PlayerPrefs.GetInt("stardust"); 
     active(); 
    } 

    void OnTriggerEnter(Collider other) 
    {  
     //Stardust 
     if (other.gameObject.CompareTag("stardust")) 
     { 
      isActive = 1; 
      PlayerPrefs.SetInt("stardust", isActive);   
      active(); 
      //other.gameObject.SetActive(false); 
      levelManager.score++; 
      levelManager.setScoreText(); 
      audioSource.Play(); 
      PlayerPrefs.SetInt("score", levelManager.score); 
     } 
    } 

    void active() 
    { 
     if (isActive == 0) //if none are collected 
     { 
      for (int i = 0; i < stardust.Length; i++) 
      { 
       stardust[i].SetActive(true); //make all visible 
      } 
     } 
     if (isActive == 1) //first one collected 
     { 
      stardust[0].SetActive(false); 
      stardust[1].SetActive(false); 
      stardust[2].SetActive(false); 
     }  
    } 
} 

당신이 비활성 할 수있는 모든 개체 설정 볼 수 있듯이,?

저는 모든 stardust에 대해 playerprefs에 단일 키를 사용하고 있습니다. 차라리 별똥별마다 열쇠를 줘야합니까?

나는 각각 자신의 방법, EventTrigger에서, 태그에 의해 하나 하나를 비교하는 각각의 확인없이 성공에 개별적으로 활성 설정을 시도

+0

[Unity에서 GameObject를 직렬화하고 저장하는 방법] 가능한 복제본 (https://stackoverflow.com/questions/36852213/how-to-serialize-and-save-a-gameobject-in-unity) –

답변

0

하이 Curstin Visagie, 그것은 늘 하나의 키와 함께 작동 는 playerprefs 값이 될 것입니다 덮어 쓰면 각 별 모양에 대한 각 키를 만들어야합니다.