Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Hide stars after collected

Discussion in 'Scripting' started by Mtrco, Jan 1, 2020.

  1. Mtrco

    Mtrco

    Joined:
    Dec 27, 2019
    Posts:
    5
    Hi guys
    I have some stars in my game that after player collected them I want inactive them next replay.
    Below is my database code
    Code (CSharp):
    1. using System.Collections;
    2. using System;
    3. using System.IO;
    4. using System.Collections.Generic;
    5.  
    6. using System.Runtime.Serialization.Formatters.Binary;
    7. using UnityEngine;
    8.  
    9. public class DataManagement : MonoBehaviour
    10. {
    11.     public static DataManagement datamanagement;
    12.  
    13.  
    14.     public int index;
    15.     public bool visible;
    16.     public GameObject ActualGameobject;
    17.     public Vector3 posision;
    18.  
    19.     List<gameData> items;
    20.     private void Awake()
    21.     {
    22.         if (datamanagement == null)
    23.         {
    24.             DontDestroyOnLoad(gameObject);
    25.             datamanagement = this;
    26.         }
    27.         else if (datamanagement != this)
    28.         {
    29.             Destroy(gameObject);
    30.         }
    31.     }
    32.  
    33.  
    34.     public void SaveData()
    35.     {
    36.         BinaryFormatter binaryForm = new BinaryFormatter();
    37.         FileStream file = File.Create(Application.persistentDataPath + "/gameInfo8.mtr");
    38.         gameData data = new gameData();
    39.  
    40.         data.index = index;
    41.         data.visible = visible;
    42.         data.ActualGameobject = ActualGameobject;
    43.         data.posision = posision;
    44.  
    45.         binaryForm.Serialize(file, data);
    46.         file.Close();
    47.     }
    48.  
    49.  
    50.     public void LoadData()
    51.     {
    52.         if (File.Exists(Application.persistentDataPath + "/gameInfo8.mtr"))
    53.         {
    54.             BinaryFormatter binaryForm = new BinaryFormatter();
    55.             FileStream file = File.Open(Application.persistentDataPath + "/gameInfo8.mtr", FileMode.Open);
    56.             gameData data = (gameData)binaryForm.Deserialize(file);
    57.             file.Close();
    58.  
    59.            
    60.  
    61.         }
    62.  
    63.         else { Debug.Log("No dataBase"); }
    64.     }
    65.  
    66.  
    67.  
    68.  
    69.     [Serializable]
    70.  
    71.     class gameData
    72.     {
    73.  
    74.         public int index;
    75.         public bool visible;
    76.         public GameObject ActualGameobject;
    77.         public Vector3 posision;
    78.  
    79.     }
    80.  
    81.  
    82.  
    83.  
    84.  
    85.  
    86.  
    87.  
    88. }
     
  2. Mtrco

    Mtrco

    Joined:
    Dec 27, 2019
    Posts:
    5
    Please help me what should I do
     
  3. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    This does not seem like a database related question to me. Didnt have a long look at your code, but you probably save your star locations in that database and then load them, right? You then instantiate star gameobjects at these locations? If so, just destroy or disable those objects when they are being collected. Next time you load the scene they will be there again anyways, unless you delete them from your database or somehow permanently delete them from your scene. Not entirely sure what your problem is otherwise.

    Also, posting 2 times in 2 minutes is a bit unnecessary. You could have just used the edit function.