Search Unity

Bug Function Somtime works somtimes not

Discussion in 'Scripting' started by unity_FUc_6LWWe7c3mw, May 17, 2021.

  1. unity_FUc_6LWWe7c3mw

    unity_FUc_6LWWe7c3mw

    Joined:
    Jan 1, 2021
    Posts:
    43
    Good day,
    i develop a game for mobile.
    I have a shop etc. where you can buy stuff, but this feature sometimes doesn't work. (On PC it always works) I have attached a script example at the bottom of the appendix.
    thanks in advance.
    Code (CSharp):
    1. //Buy- Manager
    2.  
    3.     public void itemKaufen1(int itemPreis)
    4.     {
    5.         if(kontoStandt >= itemPreis)
    6.         {
    7.             kontoStandt = kontoStandt - itemPreis;
    8.             //In klammern wie viel du von diesem Object bekommst;.
    9.             myInventar.ChangeItem1(1);
    10.             item1istGekauft = 1;
    11.             SaveManager.instance.item1istGekauft = item1istGekauft;
    12.             SaveManager.instance.item1 = myInventar.item1;
    13.             SaveManager.instance.Save();
    14.         }
    15.  
    16.         if(kontoStandt <= itemPreis)
    17.         {
    18.             Debug.Log("Dont Work");
    19.         }
    20.         //Kontostandt überprüfen;
    21.     }
    22.  
    23.  
    24. //Save Manager
    25.  
    26.     public static SaveManager instance { get; private set; }//r
    27.  
    28.     //Data to Save
    29.     public int LevelBuyed;
    30.     public bool Character01isbuyed;
    31.     public int WhichLevel;
    32.     public int money;
    33.     public int item1istGekauft;
    34.     public int item1;//r
    35.  
    36.  
    37.     //Start usw.
    38.     private void Awake()
    39.     {
    40.         if (instance != null && instance != this)//r
    41.             Destroy(gameObject);//r
    42.         else//r
    43.         instance = this;//r
    44.         DontDestroyOnLoad(gameObject);//r
    45.         Load();//r
    46.     }
    47.  
    48.     //Funktionen
    49.     public void Load()//r
    50.     {
    51.         if(File.Exists(Application.persistentDataPath + "/PlayerInfo.dat"))//r
    52.         {
    53.             BinaryFormatter bf = new BinaryFormatter();//r
    54.             FileStream file = File.Open(Application.persistentDataPath + "/PlayerInfo.dat", FileMode.Open);//r
    55.             PlayerData_Storage data = (PlayerData_Storage)bf.Deserialize(file);//r
    56.  
    57.             LevelBuyed = data.LevelBuyed;
    58.             Character01isbuyed = data.Character01isbuyed;
    59.             WhichLevel = data.WhichLevel;
    60.             money = data.money;
    61.             item1istGekauft = data.item1istGekauft;
    62.             item1 = data.item1;//r
    63.  
    64.             file.Close();//r
    65.  
    66.         }
    67.  
    68.     }
    69.  
    70.     public void Save()
    71.     {
    72.         BinaryFormatter bf = new BinaryFormatter();//r
    73.         FileStream file = File.Create(Application.persistentDataPath + "/PlayerInfo.dat");//r
    74.         PlayerData_Storage data = new PlayerData_Storage();//r
    75.  
    76.         data.LevelBuyed = LevelBuyed;
    77.         data.Character01isbuyed = Character01isbuyed;
    78.         data.WhichLevel = WhichLevel;
    79.         data.money = money;
    80.         data.item1istGekauft = item1istGekauft;
    81.         data.item1 = item1;//r
    82.  
    83.         bf.Serialize(file, data);//r
    84.         file.Close();//r
    85.     }
    86. }
    87.  
    88. //Neue Classe
    89. [Serializable] //r
    90. class PlayerData_Storage //r
    91. {
    92.     public int LevelBuyed;
    93.     public int WhichLevel;
    94.     public bool Character01isbuyed;
    95.     public int money;
    96.     public int item1istGekauft;
    97.     public int item1;//R
    98. }
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    In what way does it not work?
     
  3. unity_FUc_6LWWe7c3mw

    unity_FUc_6LWWe7c3mw

    Joined:
    Jan 1, 2021
    Posts:
    43
    The Button where white and the function does not work.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
  5. unity_FUc_6LWWe7c3mw

    unity_FUc_6LWWe7c3mw

    Joined:
    Jan 1, 2021
    Posts:
    43
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
  7. unity_FUc_6LWWe7c3mw

    unity_FUc_6LWWe7c3mw

    Joined:
    Jan 1, 2021
    Posts:
    43

    Attached Files:

  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    there should be hundreds of lines, and it keeps printing more,
    and can see debug logs, errors there:

     
  9. unity_FUc_6LWWe7c3mw

    unity_FUc_6LWWe7c3mw

    Joined:
    Jan 1, 2021
    Posts:
    43
    Ok, but there is no error and nothing else i dont no how to solve this problem.