Search Unity

Resolved Cannot enter playmode because of nonexistent compiler errors

Discussion in 'Scripting' started by NOT_A_ROBOT1101, Jun 24, 2020.

  1. NOT_A_ROBOT1101

    NOT_A_ROBOT1101

    Joined:
    Jun 18, 2020
    Posts:
    39
    When I try to enter playmode to see if my program works, an error message popped up in the console saying:

    All compiler errors have to be fixed before you can enter playmode!
    UnityEditor.SceneView:ShowCompileErrorNotification() (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:2935)

    I double-checked in Visual Studio for compiler or coding errors. There are none. No red lines, no error warnings, not a single indication of an error.

    I use Unity 2018.4.23f1 LTS, someone in the internet said it was more stable.

    I am new to coding, so maybe something happened that I didn't know about.
    Here's my code (i only use 1 script):

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Collections;
    4. using System.IO;
    5. using System.Resources;
    6. using UnityEngine;
    7. using UnityEngine.UI;
    8. using UnityEngine.Advertisements;
    9. using BayatGames.SaveGameFree;
    10. using System.Runtime.Serialization.Formatters.Binary;
    11.  
    12. public class MoneyManager : MonoBehaviour, IUnityAdsListener
    13. {
    14.     public string[] tempArray;
    15.     public GameObject newCPUPanel;
    16.     public GameObject cpuProductionCostPanel;
    17.     public GameObject adButton;
    18.     public GameObject prestigePanel;
    19.     public GameObject prestigeConfirmationPanel;
    20.     public InputField newCPUName;
    21.     public InputField newCPUClock;
    22.     public InputField newCPUCost;
    23.     public Text moneyText;
    24.     public Text moneyExpText;
    25.     public Text cpuProductionCostText;
    26.     public Text cpuClockUpgradeText;
    27.     public Text maxCPUClockText;
    28.     public Text cpuCoreText;
    29.     public Text transistorMiniaturizationUpgradeText;
    30.     public Text socketUpgradeText;
    31.     public Text cacheUpgradeText;
    32.     public Text watchAdText;
    33.     public Text prestigeText1;
    34.     public Text prestigeText3;
    35.     public Text prestigeText4;
    36.     public double money;
    37.     public double shortMoney;
    38.     public string moneyExp;
    39.     public double cpuCost;
    40.     public string newCPUNameString;
    41.     public double newCPUClockDouble;
    42.     public double newCPUCostDouble;
    43.     public int newCPUCores;
    44.     public bool isSellingCPU;
    45.     public double customerBuyProbability;
    46.     public double maxCPUClock;
    47.     public double cpuProductionCost;
    48.     public bool isBankrupt;
    49.     public int clockSpeedUpgradeLevel;
    50.     public int coreCountUpgradeLevel;
    51.     public int transistorMiniaturizationUpgradeLevel;
    52.     public int socketUpgradeLevel;
    53.     public int cacheUpgradeLevel;
    54.     public double clockSpeedUpgradeCost;
    55.     public double coreCountUpgradeCost;
    56.     public double transistorMiniaturizationUpgradeCost;
    57.     public double socketUpgradeCost;
    58.     public double cacheUpgradeCost;
    59.     public double maxCPUCoreCount;
    60.     public double transistorSize;
    61.     public string transistorSizeExpString;
    62.     private double transistorValue;
    63.     public string socketType;
    64.     public double socketHoles;
    65.     public double socketSpeed;
    66.     public double cacheAmount;
    67.     public string cacheSizeExp;
    68.     public double cacheSize;
    69.     public int nextTransistorSize;
    70.     public string nextTransistorSizeExpString;
    71.     public string nextSocketType;
    72.     public double nextSocketHoles;
    73.     public string nextCacheSizeExp;
    74.     public double nextCacheSize;
    75.     public string saveFileContents;
    76.     public double adReward;
    77.     public double prestigePoints;
    78.     public double nextPrestigePoints;
    79.     public double prestigePointBonus;
    80.     public double moneyMade;
    81.     private int temp;
    82.  
    83.     void IUnityAdsListener.OnUnityAdsDidError(string message) {UnityEngine.Debug.Log("Unity Ad encountered an error, message is " + message);}
    84.  
    85.     void IUnityAdsListener.OnUnityAdsReady(string placementId) {UnityEngine.Debug.Log("Unity Ad Ready, placementId is " + placementId);}
    86.  
    87.     void IUnityAdsListener.OnUnityAdsDidStart(string placementId) {UnityEngine.Debug.Log("Unity Ad Started, placementId is " + placementId);}
    88.  
    89.     void IUnityAdsListener.OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    90.     {
    91.         if (showResult == ShowResult.Finished)
    92.         {
    93.             AdWatched();
    94.             UnityEngine.Debug.Log("Unity Ad Finished");
    95.         }
    96.         if(showResult == ShowResult.Failed)
    97.         {
    98.             UnityEngine.Debug.Log("Unity Ad Failed");
    99.         }
    100.         if(showResult == ShowResult.Skipped)
    101.         {
    102.             UnityEngine.Debug.Log("Unity Ad Skipped");
    103.         }
    104.         UnityEngine.Debug.Log("placementId is " + placementId);
    105.     }
    106.  
    107.     public void Start()
    108.     {
    109.         SaveData.RunThisOnceToBuildTheInitailFile();
    110.         temp = 0;
    111.         isSellingCPU = false;
    112.         newCPUPanel.SetActive(false); // closes cpu panel
    113.         cpuProductionCostPanel.SetActive(false); // closes cpu production cost panel
    114.         prestigeConfirmationPanel.SetActive(false); // closes prestige confirmation panel
    115.         prestigePanel.SetActive(false); // closes prestige panel
    116.         money = 10000.0; // starting money
    117.         maxCPUCoreCount = 1;
    118.         cpuCost = 0.0;
    119.         maxCPUClock = 4;
    120.         cpuProductionCost = 0;
    121.         transistorSize = 5;
    122.         transistorSizeExpString = "micro";
    123.         socketType = "DIP";
    124.         nextSocketType = "DIP";
    125.         socketHoles = 16;
    126.         cacheSize = 1;
    127.         cacheSizeExp = " kilo";
    128.         cacheAmount = 1000;
    129.         clockSpeedUpgradeCost = 250000;
    130.         coreCountUpgradeCost = 5000000;
    131.         transistorMiniaturizationUpgradeCost = 500000;
    132.         socketUpgradeCost = 100000;
    133.         cacheUpgradeCost = 200000;
    134.         nextCacheSizeExp = cacheSizeExp;
    135.         cacheUpgradeLevel = 0;
    136.         SaveData.Load();
    137.         Advertisement.AddListener(this);
    138.         Advertisement.Initialize("3665207", false);
    139.         SaveData.saveVars.adReward = adReward;
    140.         transistorValue = transistorSizeExpString switch
    141.         {
    142.             "micro" => 0.000001 * transistorSize,
    143.             "nano" => 0.000000001 * transistorSize,
    144.             "pico" => 0.000000000001 * transistorSize,
    145.             _ => 0,
    146.         };
    147.         switch (socketType)
    148.         {
    149.             case "DIP":
    150.                 socketSpeed = socketHoles;
    151.                 break;
    152.             case "PLCC":
    153.                 socketSpeed = 15 * socketHoles;
    154.                 break;
    155.             case "PGA":
    156.                 socketSpeed = 30 * socketHoles;
    157.                 break;
    158.             case "LGA":
    159.                 socketSpeed = 50 * socketHoles;
    160.                 break;
    161.             default:
    162.                 break;
    163.         }
    164.         cpuClockUpgradeText.text = "Upgrade Max CPU Clock Speed\nLevel:" + clockSpeedUpgradeLevel + "\n" + maxCPUClock + " kHz -> " + (maxCPUClock + Math.Ceiling(maxCPUClock / 4)) + " kHz\nPrice: $" + Math.Ceiling(clockSpeedUpgradeCost);
    165.         cpuCoreText.text = "Upgrade Core Count\nLevel " + coreCountUpgradeLevel + "\n" + maxCPUCoreCount + " cores => " + (Math.Ceiling(Convert.ToDouble(maxCPUCoreCount) / 4) + maxCPUCoreCount) + " cores\nCost: $" + coreCountUpgradeCost;
    166.         if (transistorMiniaturizationUpgradeLevel < 26) { transistorMiniaturizationUpgradeText.text = "Upgrade Transistor Size\nLevel " + transistorMiniaturizationUpgradeLevel + "\n" + transistorSize + " " + transistorSizeExpString + "meters => " + nextTransistorSize + " " + nextTransistorSizeExpString + "meters" + "\nCost: $" + transistorMiniaturizationUpgradeCost; } else { transistorMiniaturizationUpgradeText.text = "Max Transistor Size Reached\n1 picometer"; }
    167.         socketUpgradeText.text = "Upgrade Socket\nLevel " + socketUpgradeLevel + "\n" + socketType + socketHoles + " => " + nextSocketType + nextSocketHoles + "\nCost: $" + socketUpgradeCost;
    168.         cacheUpgradeText.text = "Upgrade Cache Size\nLevel " + cacheUpgradeLevel + "\n" + cacheSize + cacheSizeExp + "bytes => " + nextCacheSize + nextCacheSizeExp + "bytes\nCost: $" + cacheUpgradeCost;
    169.         customerBuyProbability = 0.000000000000075 * (1 / transistorValue) * newCPUClockDouble * maxCPUCoreCount * socketSpeed * cacheAmount / (1.25 * cpuCost);
    170.         prestigePointBonus = 0.1 * prestigePoints;
    171.     }
    172.  
    173.     public void Update()
    174.     {
    175.         SaveData.saveVars.tempArray = tempArray;
    176.         SaveData.saveVars.money = money;
    177.         SaveData.saveVars.moneyExp = moneyExp;
    178.         SaveData.saveVars.cpuProductionCost = cpuProductionCost;
    179.         SaveData.saveVars.maxCPUClock = maxCPUClock;
    180.         SaveData.saveVars.money = money;
    181.         SaveData.saveVars.shortMoney = shortMoney;
    182.         SaveData.saveVars.moneyExp = moneyExp;
    183.         SaveData.saveVars.cpuCost = cpuCost;
    184.         SaveData.saveVars.newCPUCores = newCPUCores;
    185.         SaveData.saveVars.isSellingCPU = isSellingCPU;
    186.         SaveData.saveVars.customerBuyProbability = customerBuyProbability;
    187.         SaveData.saveVars.maxCPUClock = maxCPUClock;
    188.         SaveData.saveVars.cpuProductionCost = cpuProductionCost;
    189.         SaveData.saveVars.isBankrupt = isBankrupt;
    190.         SaveData.saveVars.clockSpeedUpgradeLevel = clockSpeedUpgradeLevel;
    191.         SaveData.saveVars.coreCountUpgradeLevel = coreCountUpgradeLevel;
    192.         SaveData.saveVars.transistorMiniaturizationUpgradeLevel = transistorMiniaturizationUpgradeLevel;
    193.         SaveData.saveVars.socketUpgradeLevel = socketUpgradeLevel;
    194.         SaveData.saveVars.cacheUpgradeLevel = cacheUpgradeLevel;
    195.         SaveData.saveVars.clockSpeedUpgradeCost = clockSpeedUpgradeCost;
    196.         SaveData.saveVars.coreCountUpgradeCost = coreCountUpgradeCost;
    197.         SaveData.saveVars.transistorMiniaturizationUpgradeCost = transistorMiniaturizationUpgradeCost;
    198.         SaveData.saveVars.socketUpgradeCost = socketUpgradeCost;
    199.         SaveData.saveVars.cacheUpgradeCost = cacheUpgradeCost;
    200.         SaveData.saveVars.maxCPUCoreCount = maxCPUCoreCount;
    201.         SaveData.saveVars.transistorSize = transistorSize;
    202.         SaveData.saveVars.transistorSizeExpString = transistorSizeExpString;
    203.         SaveData.saveVars.transistorValue = transistorValue;
    204.         SaveData.saveVars.socketType = socketType;
    205.         SaveData.saveVars.socketHoles = socketHoles;
    206.         SaveData.saveVars.socketSpeed = socketSpeed;
    207.         SaveData.saveVars.cacheAmount = cacheAmount;
    208.         SaveData.saveVars.cacheSizeExp = cacheSizeExp;
    209.         SaveData.saveVars.cacheSize = cacheSize;
    210.         SaveData.saveVars.nextTransistorSize = nextTransistorSize;
    211.         SaveData.saveVars.nextTransistorSizeExpString = nextTransistorSizeExpString;
    212.         SaveData.saveVars.nextSocketType = nextSocketType;
    213.         SaveData.saveVars.nextSocketHoles = nextSocketHoles;
    214.         SaveData.saveVars.nextCacheSizeExp = nextCacheSizeExp;
    215.         SaveData.saveVars.nextCacheSize = nextCacheSize;
    216.         SaveData.saveVars.saveFileContents = saveFileContents;
    217.         SaveData.saveVars.adReward = adReward;
    218.         SaveData.saveVars.prestigePoints = prestigePoints;
    219.         SaveData.saveVars.nextPrestigePoints = nextPrestigePoints;
    220.         SaveData.saveVars.prestigePointBonus = prestigePointBonus;
    221.         SaveData.saveVars.moneyMade = moneyMade;
    222.         SaveData.saveVars.temp = temp;
    223.         shortMoney = money / Math.Pow(1000, Math.Floor(Math.Log(money, 1000)));
    224.         switch(Math.Floor(Math.Log(money, 1000)))
    225.         {
    226.             case 1:
    227.                 moneyExp = "thousand";
    228.                 break;
    229.             case 2:
    230.                 moneyExp = "million";
    231.                 break;
    232.             case 3:
    233.                 moneyExp = "billion";
    234.                 break;
    235.             case 4:
    236.                 moneyExp = "trillion";
    237.                 break;
    238.             case 5:
    239.                 moneyExp = "quadrillion";
    240.                 break;
    241.             case 6:
    242.                 moneyExp = "quintillion";
    243.                 break;
    244.             case 7:
    245.                 moneyExp = "sextillion";
    246.                 break;
    247.             case 8:
    248.                 moneyExp = "septillion";
    249.                 break;
    250.             case 9:
    251.                 moneyExp = "octillion";
    252.                 break;
    253.             case 10:
    254.                 moneyExp = "nonillion";
    255.                 break;
    256.             case 11:
    257.                 moneyExp = "decillion";
    258.                 break;
    259.             case 12:
    260.                 moneyExp = "undecillion";
    261.                 break;
    262.             case 13:
    263.                 moneyExp = "tredecillion";
    264.                 break;
    265.             case 14:
    266.                 moneyExp = "quattuordecillion";
    267.                 break;
    268.             case 15:
    269.                 moneyExp = "quindecillion";
    270.                 break;
    271.             case 16:
    272.                 moneyExp = "sexdecillion";
    273.                 break;
    274.             case 17:
    275.                 moneyExp = "septendecillion";
    276.                 break;
    277.             case 18:
    278.                 moneyExp = "octodecillion";
    279.                 break;
    280.             case 19:
    281.                 moneyExp = "novemdecillion";
    282.                 break;
    283.             case 20:
    284.                 moneyExp = "vigintillion";
    285.                 break;
    286.             case 21:
    287.                 moneyExp = "unvigintillion";
    288.                 break;
    289.             case 22:
    290.                 moneyExp = "duovigintillion";
    291.                 break;
    292.             case 23:
    293.                 moneyExp = "tresvigintillion";
    294.                 break;
    295.             case 24:
    296.                 moneyExp = "quattuorvigintillion";
    297.                 break;
    298.             case 25:
    299.                 moneyExp = "quinvigintillion";
    300.                 break;
    301.             case 26:
    302.                 moneyExp = "sexvigintillion";
    303.                 break;
    304.             case 27:
    305.                 moneyExp = "septenvigintillion";
    306.                 break;
    307.             case 28:
    308.                 moneyExp = "octovigintillion";
    309.                 break;
    310.             case 29:
    311.                 moneyExp = "novemvigintillion";
    312.                 break;
    313.             case 30:
    314.                 moneyExp = "trigintillion";
    315.                 break;
    316.             default:
    317.                 if(Math.Floor(Math.Log(money, 1000)) < 1)
    318.                 {
    319.                     moneyExp = "";
    320.                 }
    321.                 else if (Math.Floor(Math.Log(money, 1000)) > 30)
    322.                 {
    323.                     moneyExp = "e+" + (Math.Log(money, 1000) * 3);
    324.                 }
    325.                 break;
    326.         }
    327.         if(money < 1000)
    328.         {
    329.             moneyText.text = "$" + Convert.ToString(Math.Floor(money * 100) / 100); // updates the money counters
    330.             moneyExpText.text = "";
    331.         }
    332.         else
    333.         {
    334.             moneyText.text = "$" + Convert.ToString(Math.Floor(shortMoney * 1000) / 1000);
    335.             moneyExpText.text = Convert.ToString(moneyExp);
    336.         }
    337.         if (isSellingCPU == true)
    338.         {
    339.             temp++;
    340.             money += ((cpuCost - cpuProductionCost) * 50000 * customerBuyProbability);
    341.             moneyMade += (cpuCost - cpuProductionCost) * 50000 * customerBuyProbability;
    342.             if (temp >= 1000)
    343.             {
    344.                 isSellingCPU = false;
    345.             }
    346.         }
    347.  
    348.         if (money <= -3000)
    349.         {
    350.             isBankrupt = true;
    351.         }
    352.         adReward = 0.0000035 * (1 / transistorValue) * maxCPUClock * maxCPUCoreCount * socketSpeed * cacheAmount;
    353.         watchAdText.text = $"Watch an ad to get ${adReward}!";
    354.         if (Advertisement.IsReady())
    355.         {
    356.             adButton.SetActive(true);
    357.         }
    358.         else
    359.         {
    360.             adButton.SetActive(false);
    361.         }
    362.  
    363.         if(Math.Floor(Math.Log(moneyMade, 50000) - 9) > 0)
    364.         {
    365.             nextPrestigePoints = Math.Floor(Math.Log(moneyMade, 50000) - 9);
    366.         }
    367.         else
    368.         {
    369.             nextPrestigePoints = 0;
    370.         }
    371.         prestigeText3.text = "You'll get\n" + nextPrestigePoints + "\nprestige points if you prestige now.";
    372.         prestigeText4.text = "You'll gain\n" + nextPrestigePoints + "\nprestige points.";
    373.     }
    374.  
    375.     public void CPUSell()
    376.     {
    377.         cpuProductionCostPanel.SetActive(false); // closes cpu production confirmation
    378.         newCPUPanel.SetActive(true); // true means panel is on, false means it is off
    379.         prestigePanel.SetActive(false); // closes prestige panel
    380.         prestigeConfirmationPanel.SetActive(false); // closes prestige confirmation panel
    381.         maxCPUClockText.text = "Choose the speed(Max: " + maxCPUClock + "kHz)";
    382.     }
    383.  
    384.     public void CPUPanelClose()
    385.     {
    386.         newCPUPanel.SetActive(false); // closes cpu panel
    387.     }
    388.  
    389.     public void CPUPanelConfirm()
    390.     {
    391.         temp = 0;
    392.         UnityEngine.Debug.Log(newCPUName.text);
    393.         newCPUNameString = newCPUName.text;
    394.         UnityEngine.Debug.Log(newCPUClock.text);
    395.         newCPUClockDouble = Convert.ToDouble(newCPUClock.text);
    396.         UnityEngine.Debug.Log(newCPUCost.text);
    397.         cpuCost = Convert.ToDouble(newCPUCost.text);
    398.         if (newCPUClockDouble <= maxCPUClock)
    399.         {
    400.             newCPUPanel.SetActive(false);  // closes cpu panel
    401.             transistorValue = transistorSizeExpString switch
    402.             {
    403.                 "micro" => 0.000001 * transistorSize,
    404.                 "nano" => 0.000000001 * transistorSize,
    405.                 "pico" => 0.000000000001 * transistorSize,
    406.                 _ => 0,
    407.             };
    408.             switch (socketType)
    409.             {
    410.                 case "DIP":
    411.                     socketSpeed = socketHoles;
    412.                     break;
    413.                 case "PLCC":
    414.                     socketSpeed = 15 * socketHoles;
    415.                     break;
    416.                 case "PGA":
    417.                     socketSpeed = 30 * socketHoles;
    418.                     break;
    419.                 case "LGA":
    420.                     socketSpeed = 50 * socketHoles;
    421.                     break;
    422.             }
    423.             customerBuyProbability = 0.000000000000075 * (1 / transistorValue) * newCPUClockDouble * maxCPUCoreCount * socketSpeed * cacheAmount / ( 1.25 * cpuCost );
    424.             cpuProductionCost = (newCPUClockDouble / maxCPUClock) * 80;
    425.             cpuProductionCostPanel.SetActive(true); //turns on cpu production cost panel
    426.             cpuProductionCostText.text = "It will require $" + cpuProductionCost + " to manufacture 1 CPU.\nAre you sure you want to sell it at $" + cpuCost + "?";
    427.         }
    428.  
    429.     }
    430.  
    431.     public void CPUProductionConfirm()
    432.     {
    433.         cpuProductionCostPanel.SetActive(false); // closes cpu production confirmation
    434.         isSellingCPU = true;
    435.     }
    436.  
    437.     public void CPUProductionCancel()
    438.     {
    439.         cpuProductionCostPanel.SetActive(false); // closes cpu production confirmation
    440.         newCPUPanel.SetActive(true); // opens back cpu panel
    441.     }
    442.  
    443.     public void ClockSpeedUpgrade()
    444.     {
    445.         if (money > clockSpeedUpgradeCost && maxCPUClock < 2000000000)
    446.         {
    447.             money -= clockSpeedUpgradeCost;
    448.             clockSpeedUpgradeLevel++;
    449.             clockSpeedUpgradeCost *= 1.25;
    450.             maxCPUClock += Math.Ceiling(maxCPUClock / 4);
    451.             cpuClockUpgradeText.text = "Upgrade Max CPU Clock Speed\nLevel:" + clockSpeedUpgradeLevel + "\n" + maxCPUClock + " kHz -> " + (maxCPUClock + Math.Ceiling(maxCPUClock / 4)) + " kHz\nPrice: $" + Convert.ToString(Math.Ceiling(clockSpeedUpgradeCost * 100) / 100);
    452.         }
    453.     }
    454.  
    455.     public void CoreCountUpgrade()
    456.     {
    457.         if (money > coreCountUpgradeCost && maxCPUCoreCount < 2000000000)
    458.         {
    459.             money -= coreCountUpgradeCost;
    460.             coreCountUpgradeLevel++;
    461.             coreCountUpgradeCost *= 1.25;
    462.             maxCPUCoreCount = Convert.ToDouble(maxCPUCoreCount + Math.Ceiling(Convert.ToDouble(maxCPUCoreCount) / 4));
    463.             cpuCoreText.text = "Upgrade Core Count\nLevel " + coreCountUpgradeLevel + "\n" + maxCPUCoreCount + " cores => " + (Math.Ceiling(Convert.ToDouble(maxCPUCoreCount) / 4) + maxCPUCoreCount) + " cores\nCost: $" + Convert.ToString(Math.Ceiling(coreCountUpgradeCost * 100) / 100);
    464.         }
    465.     }
    466.  
    467.     public void TransistorMiniaturizationUpgrade()
    468.     {
    469.         if (money > transistorMiniaturizationUpgradeCost)
    470.         {
    471.             if (!(transistorSizeExpString == "pico" && transistorSize == 1))
    472.             {
    473.                 money -= transistorMiniaturizationUpgradeCost;
    474.                 transistorMiniaturizationUpgradeLevel++;
    475.                 transistorMiniaturizationUpgradeCost *= 1.3;
    476.                 switch (transistorSize)
    477.                 {
    478.                     case 750:
    479.                         transistorSize = 500;
    480.                         break;
    481.                     case 500:
    482.                         transistorSize = 250;
    483.                         break;
    484.                     case 250:
    485.                         transistorSize = 150;
    486.                         break;
    487.                     case 150:
    488.                         transistorSize = 100;
    489.                         break;
    490.                     case 100:
    491.                         transistorSize = 75;
    492.                         break;
    493.                     case 75:
    494.                         transistorSize = 50;
    495.                         break;
    496.                     case 50:
    497.                         transistorSize = 25;
    498.                         break;
    499.                     case 25:
    500.                         transistorSize = 10;
    501.                         break;
    502.                     case 10:
    503.                         transistorSize = 5;
    504.                         break;
    505.                     case 5:
    506.                         transistorSize = 2;
    507.                         break;
    508.                     case 2:
    509.                         transistorSize = 1;
    510.                         break;
    511.                     case 1:
    512.                         if (transistorSizeExpString != "pico")
    513.                         {
    514.                             switch (transistorSizeExpString)
    515.                             {
    516.                                 case "micro":
    517.                                     transistorSizeExpString = "nano";
    518.                                     transistorSize = 750;
    519.                                     break;
    520.                                 case "nano":
    521.                                     transistorSizeExpString = "pico";
    522.                                     transistorSize = 750;
    523.                                     break;
    524.                                 default:
    525.                                     transistorSize = 1;
    526.                                     break;
    527.                             }
    528.                         }
    529.                         break;
    530.                 }
    531.  
    532.             }
    533.  
    534.             switch (transistorSize)
    535.             {
    536.                 case 750:
    537.                     nextTransistorSize = 500;
    538.                     break;
    539.                 case 500:
    540.                     nextTransistorSize = 250;
    541.                     break;
    542.                 case 250:
    543.                     nextTransistorSize = 150;
    544.                     break;
    545.                 case 150:
    546.                     nextTransistorSize = 100;
    547.                     break;
    548.                 case 100:
    549.                     nextTransistorSize = 75;
    550.                     break;
    551.                 case 75:
    552.                     nextTransistorSize = 50;
    553.                     break;
    554.                 case 50:
    555.                     nextTransistorSize = 25;
    556.                     break;
    557.                 case 25:
    558.                     nextTransistorSize = 10;
    559.                     break;
    560.                 case 10:
    561.                     nextTransistorSize = 5;
    562.                     break;
    563.                 case 5:
    564.                     nextTransistorSize = 2;
    565.                     break;
    566.                 case 2:
    567.                     nextTransistorSize = 1;
    568.                     break;
    569.                 case 1:
    570.                     nextTransistorSize = 750;
    571.                     switch (transistorSizeExpString)
    572.                     {
    573.                         case "nano":
    574.                             nextTransistorSizeExpString = "pico";
    575.                             break;
    576.                         case "pico":
    577.                             nextTransistorSizeExpString = "yotta";
    578.                             nextTransistorSize = 9001;
    579.                             break;
    580.                         case "micro":
    581.                             nextTransistorSizeExpString = "nano";
    582.                             break;
    583.                     }
    584.                     break;
    585.             }
    586.             if (transistorMiniaturizationUpgradeLevel < 26) { transistorMiniaturizationUpgradeText.text = "Upgrade Transistor Size\nLevel " + transistorMiniaturizationUpgradeLevel + "\n" + transistorSize + " " + transistorSizeExpString + "meters => " + nextTransistorSize + " " + nextTransistorSizeExpString + "meters" + "\nCost: $" + Convert.ToString(Math.Ceiling(transistorMiniaturizationUpgradeCost * 100) / 100); } else { transistorMiniaturizationUpgradeText.text = "Max Transistor Size Reached\n1 picometer"; }
    587.         }
    588.  
    589.     }
    590.  
    591.     public void SocketUpgrade()
    592.     {
    593.         if (money > socketUpgradeCost)
    594.         {
    595.             money -= socketUpgradeCost;
    596.             socketUpgradeLevel++;
    597.             socketUpgradeCost *= 1.2;
    598.             if (socketType == "LGA" | socketHoles < 1000)
    599.             {
    600.                 socketHoles = 2 * socketHoles;
    601.             }
    602.             else
    603.             {
    604.                 if (socketType == "DIP")
    605.                 {
    606.                     socketType = "PLCC";
    607.                     socketHoles = 64;
    608.                 }
    609.                 else if (socketType == "PLCC")
    610.                 {
    611.                     socketType = "PGA";
    612.                     socketHoles = 256;
    613.                 }
    614.                 else if (socketType == "PGA")
    615.                 {
    616.                     socketType = "LGA";
    617.                     socketHoles = 512;
    618.                 }
    619.             }
    620.             if (socketType == "LGA" | socketHoles < 1000)
    621.             {
    622.                 nextSocketHoles = 2 * socketHoles;
    623.             }
    624.             else
    625.             {
    626.                 if (socketType == "DIP")
    627.                 {
    628.                     nextSocketType = "PLCC";
    629.                     nextSocketHoles = 64;
    630.                 }
    631.                 else if (socketType == "PLCC")
    632.                 {
    633.                     nextSocketType = "PGA";
    634.                     nextSocketHoles = 256;
    635.                 }
    636.                 else if (socketType == "PGA")
    637.                 {
    638.                     nextSocketType = "LGA";
    639.                     nextSocketHoles = 512;
    640.                 }
    641.             }
    642.             socketUpgradeText.text = "Upgrade Socket\nLevel " + socketUpgradeLevel + "\n" + socketType + socketHoles + " => " + nextSocketType + nextSocketHoles + "\nCost: $" + Convert.ToString(Math.Ceiling(socketUpgradeCost * 100) / 100);
    643.         }
    644.     }
    645.  
    646.     public void CacheUpgrade()
    647.     {
    648.         if(money > cacheUpgradeCost)
    649.         {
    650.             money -= cacheUpgradeCost;
    651.             cacheUpgradeLevel++;
    652.             switch (cacheSize)
    653.             {
    654.                 case 1:
    655.                     cacheSize = 2;
    656.                     break;
    657.                 case 2:
    658.                     cacheSize = 5;
    659.                     break;
    660.                 case 5:
    661.                     cacheSize = 10;
    662.                     break;
    663.                 case 10:
    664.                     cacheSize = 25;
    665.                     break;
    666.                 case 25:
    667.                     cacheSize = 50;
    668.                     break;
    669.                 case 50:
    670.                     cacheSize = 75;
    671.                     break;
    672.                 case 75:
    673.                     cacheSize = 100;
    674.                     break;
    675.                 case 100:
    676.                     cacheSize = 150;
    677.                     break;
    678.                 case 150:
    679.                     cacheSize = 200;
    680.                     break;
    681.                 case 200:
    682.                     cacheSize = 250;
    683.                     break;
    684.                 case 250:
    685.                     cacheSize = 350;
    686.                     break;
    687.                 case 350:
    688.                     cacheSize = 500;
    689.                     break;
    690.                 case 500:
    691.                     cacheSize = 750;
    692.                     switch (cacheSizeExp)
    693.                     {
    694.                         case " yotta":
    695.                             nextCacheSizeExp = "---";
    696.                             break;
    697.                         case " zetta":
    698.                             nextCacheSizeExp = " yotta";
    699.                             break;
    700.                         case " exa":
    701.                             nextCacheSizeExp = " zetta";
    702.                             break;
    703.                         case " peta":
    704.                             nextCacheSizeExp = " exa";
    705.                             break;
    706.                         case " tera":
    707.                             nextCacheSizeExp = " peta";
    708.                             break;
    709.                         case " giga":
    710.                             nextCacheSizeExp = " tera";
    711.                             break;
    712.                         case " mega":
    713.                             nextCacheSizeExp = " giga";
    714.                             break;
    715.                         case " kilo":
    716.                             nextCacheSizeExp = " mega";
    717.                             break;
    718.                     }
    719.                     break;
    720.                 case 750:
    721.                     cacheSize = 1;
    722.                     switch (cacheSizeExp)
    723.                     {
    724.                         case " yotta":
    725.                             cacheSize = 999;
    726.                             nextCacheSize = 0;
    727.                             nextCacheSizeExp = "---";
    728.                             break;
    729.                         case " zetta":
    730.                             cacheSizeExp = " yotta";
    731.                             break;
    732.                         case " exa":
    733.                             cacheSizeExp = " zetta";
    734.                             break;
    735.                         case " peta":
    736.                             cacheSizeExp = " exa";
    737.                             break;
    738.                         case " tera":
    739.                             cacheSizeExp = " peta";
    740.                             break;
    741.                         case " giga":
    742.                             cacheSizeExp = " tera";
    743.                             break;
    744.                         case " mega":
    745.                             cacheSizeExp = " giga";
    746.                             break;
    747.                         case " kilo":
    748.                             cacheSizeExp = " mega";
    749.                             break;
    750.  
    751.                     }
    752.                     break;
    753.                 default:
    754.                     money += cacheUpgradeCost;
    755.                     break;
    756.             }
    757.             switch (cacheSizeExp)
    758.             {
    759.                 case " yotta":
    760.                     cacheAmount = 1000000000000000000000000.0 * cacheSize;
    761.                     break;
    762.                 case " zetta":
    763.                     cacheAmount = 1000000000000000000000.0 * cacheSize;
    764.                     break;
    765.                 case " exa":
    766.                     cacheAmount = 1000000000000000000.0 * cacheSize;
    767.                     break;
    768.                 case " peta":
    769.                     cacheAmount = 1000000000000000.0 * cacheSize;
    770.                     break;
    771.                 case " tera":
    772.                     cacheAmount = 1000000000000.0 * cacheSize;
    773.                     break;
    774.                 case " giga":
    775.                     cacheAmount = 1000000000.0 * cacheSize;
    776.                     break;
    777.                 case " mega":
    778.                     cacheAmount = 1000000.0 * cacheSize;
    779.                     break;
    780.                 case " kilo":
    781.                     cacheAmount = 1000.0 * cacheSize;
    782.                     break;
    783.             }
    784.             cacheUpgradeCost = 1.2 * cacheUpgradeCost;
    785.             cacheUpgradeText.text = "Upgrade Cache Size\nLevel " + cacheUpgradeLevel + "\n" + cacheSize + cacheSizeExp + "bytes => " + nextCacheSize + nextCacheSizeExp + "bytes\nCost: $" + Convert.ToString(Math.Ceiling(cacheUpgradeCost * 100) / 100);
    786.         }
    787.     }
    788.  
    789.     public void PrestigePanelOpen()
    790.     {
    791.         prestigePanel.SetActive(true); // opens prestige panel
    792.         prestigeConfirmationPanel.SetActive(false); // closes prestige confirmation panel
    793.         newCPUPanel.SetActive(false); // closes cpu panels
    794.         cpuProductionCostPanel.SetActive(false);
    795.         prestigeText1.text = "You have\n" + prestigePoints + "\nprestige points.";
    796.     }
    797.  
    798.     public void PrestigePanelClose()
    799.     {
    800.         prestigePanel.SetActive(false); // closes prestige panel
    801.     }
    802.  
    803.     public void Prestige()
    804.     {
    805.         prestigePanel.SetActive(false); // closes prestige panel
    806.         prestigeConfirmationPanel.SetActive(true); // opens prestige confirmation panel
    807.  
    808.     }
    809.  
    810.     public void ConfirmPrestige()
    811.     {
    812.         if(prestigePoints > 0)
    813.         {
    814.             prestigeConfirmationPanel.SetActive(false);
    815.             prestigePoints += nextPrestigePoints;
    816.             temp = 0;
    817.             money = 10000.0; // starting money
    818.             maxCPUCoreCount = 1;
    819.             cpuCost = 0.0;
    820.             maxCPUClock = 4;
    821.             cpuProductionCost = 0;
    822.             transistorSize = 5;
    823.             transistorSizeExpString = "micro";
    824.             socketType = "DIP";
    825.             nextSocketType = "DIP";
    826.             socketHoles = 16;
    827.             cacheSize = 1;
    828.             cacheSizeExp = " kilo";
    829.             cacheAmount = 1000;
    830.             clockSpeedUpgradeCost = 250000;
    831.             coreCountUpgradeCost = 5000000;
    832.             transistorMiniaturizationUpgradeCost = 500000;
    833.             socketUpgradeCost = 100000;
    834.             cacheUpgradeCost = 200000;
    835.             nextCacheSizeExp = cacheSizeExp;
    836.             cacheUpgradeLevel = 0;
    837.         }
    838.         else
    839.         {
    840.             UnityEngine.Debug.Log("Player tried to prestige when it he/she will get 0 prestige points");
    841.         }
    842.     }
    843.  
    844.     public void CancelPrestige()
    845.     {
    846.         prestigeConfirmationPanel.SetActive(false);
    847.         prestigePanel.SetActive(true);
    848.     }
    849.  
    850.     public void ShowAd()
    851.     {
    852.         UnityEngine.Debug.Log("ShowAd() is triggered");
    853.         Advertisement.Show("rewardedVideo");
    854.         AdWatched();
    855.     }
    856.  
    857.     public void AdWatched()
    858.     {
    859.         UnityEngine.Debug.Log("AdWatched(); has been run");
    860.         money += adReward;
    861.         moneyMade += adReward;
    862.     }
    863.  
    864.     public void SaveTheGame()
    865.     {
    866.         SaveData.Save(); // third try on saving o.O
    867.     }
    868.  
    869.     public void LoadTheGame()
    870.     {
    871.         SaveData.Load(); //untested 3rd try on loading o.O
    872.     }
    873.  
    874.  
    875.     [System.Serializable]
    876.     public class SaveData
    877.     {
    878.         // Creates a public reference that can be used to set the data
    879.         public static SaveVariables saveVars = new SaveVariables();
    880.         // Get the path to the save file
    881.         public static string GetPath()
    882.         {
    883.             return Application.persistentDataPath + saveVars.directory;
    884.         }
    885.         // Return the filename of the save file.
    886.         public static string GetFileName()
    887.         {
    888.             return saveVars.playerName + saveVars.extention;
    889.         }
    890.         // Call this once before anything else is done.
    891.         // This will create the new file and make sure the directory is correct.
    892.         public static void RunThisOnceToBuildTheInitailFile()
    893.         {
    894.             var path = GetPath();
    895.             var fileName = GetFileName();
    896.             var fullpath = (Path.Combine(path, fileName));
    897.             if (!Directory.Exists(path))
    898.             {
    899.                 Directory.CreateDirectory(path);
    900.             }
    901.             if (File.Exists(fullpath))
    902.             {
    903.                 Debug.Log("File named " + fullpath + " already exists");
    904.                 return;
    905.             }
    906.             else Debug.Log(fullpath);
    907.             // If the player has never played before write the defaults to the save data and
    908.             //     then save the state so the game will start fresh
    909.             Save();
    910.         }
    911.         // Save the data.
    912.         public static void Save()
    913.         {
    914.             var path = GetPath();
    915.             var fileName = GetFileName();
    916.             var fullpath = (Path.Combine(path, fileName));
    917.             BinaryFormatter bf = new BinaryFormatter();
    918.             // Save the written variabes to the disk.
    919.             using (var file = File.Create(fullpath))
    920.             {
    921.                 // Take the SaveVariables class and write the variables to disk.
    922.                 bf.Serialize(file, saveVars);
    923.             }
    924.             Debug.Log("Data Saved in Directory" + fullpath);
    925.         }
    926.         // Load the data.
    927.         public static void Load()
    928.         {
    929.             var path = GetPath();
    930.             var fileName = GetFileName();
    931.             var fullpath = (Path.Combine(path, fileName));
    932.             // Load the file and write the data to the class vars.
    933.             if (File.Exists(fullpath))
    934.             {
    935.                 FileStream inStr = new FileStream(fullpath, FileMode.Open);
    936.                 BinaryFormatter bf = new BinaryFormatter();
    937.                 // Load the file as SaveData class
    938.                 var data = bf.Deserialize(inStr) as SaveVariables;
    939.                 // write the saved data to the saveVars class reference
    940.                 saveVars = data;
    941.                 Debug.Log("Data Loaded From Directory" + fullpath);
    942.                 inStr.Close();
    943.             }
    944.             else
    945.                 Debug.Log(fullpath + "Doesnt Exist To Load");
    946.         }
    947.         // To delete the file.
    948.         public static void Delete()
    949.         {
    950.             var path = GetPath();
    951.             var fileName = GetFileName();
    952.             var fullpath = (Path.Combine(path, fileName));
    953.             // Delete the file from the disk.
    954.             if (File.Exists(fullpath))
    955.             {
    956.                 File.Delete(fullpath);
    957.                 Debug.Log("File Deleted " + fullpath);
    958.                 // Create a new class to reference that will load the defualts back
    959.                 saveVars = new SaveVariables();
    960.             }
    961.             else Debug.Log("No File To Delete");
    962.         }
    963.         [System.Serializable]
    964.         public class SaveVariables
    965.         {
    966.             public readonly string directory = "/CPU Seller Simulator/";
    967.             public readonly string playerName = "gamedata";
    968.             public readonly string extention = ".bin";
    969.             // PUT VARIABLES HERE!!!
    970.             //         |
    971.             //         |
    972.             //        \|/
    973.             //         V
    974.  
    975.             public string[] tempArray;
    976.             public double money = 10000;
    977.             public double shortMoney = 10;
    978.             public string moneyExp = "thousand";
    979.             public double cpuCost = 0.0;
    980.             public string newCPUNameString = "Stop hacking, you hacker!";
    981.             public double newCPUClockDouble = 0.0;
    982.             public double newCPUCostDouble = 0.0;
    983.             public int newCPUCores;
    984.             public bool isSellingCPU = false;
    985.             public double customerBuyProbability;
    986.             public double maxCPUClock = 4.0;
    987.             public double cpuProductionCost = 0.0;
    988.             public bool isBankrupt = false;
    989.             public int clockSpeedUpgradeLevel = 0;
    990.             public int coreCountUpgradeLevel = 0;
    991.             public int transistorMiniaturizationUpgradeLevel = 0;
    992.             public int socketUpgradeLevel = 0;
    993.             public int cacheUpgradeLevel = 0;
    994.             public double clockSpeedUpgradeCost = 250000;
    995.             public double coreCountUpgradeCost = 5000000;
    996.             public double transistorMiniaturizationUpgradeCost = 500000;
    997.             public double socketUpgradeCost = 100000;
    998.             public double cacheUpgradeCost = 200000;
    999.             public double maxCPUCoreCount = 1;
    1000.             public double transistorSize = 5;
    1001.             public string transistorSizeExpString = "micro";
    1002.             public double transistorValue = 0.000005;
    1003.             public string socketType = "DIP";
    1004.             public double socketHoles = 16;
    1005.             public double socketSpeed = 16;
    1006.             public double cacheAmount = 1000;
    1007.             public string cacheSizeExp = "kilo";
    1008.             public double cacheSize = 1;
    1009.             public int nextTransistorSize;
    1010.             public string nextTransistorSizeExpString;
    1011.             public string nextSocketType;
    1012.             public double nextSocketHoles;
    1013.             public string nextCacheSizeExp = "kilo";
    1014.             public double nextCacheSize;
    1015.             public string saveFileContents;
    1016.             public double adReward = 0.0;
    1017.             public double prestigePoints = 0.0;
    1018.             public double nextPrestigePoints;
    1019.             public double prestigePointBonus = 0.0;
    1020.             public double moneyMade = 0.0;
    1021.             public int temp = 0;
    1022.         }
    1023.     }
    1024. }
    Sorry if it worries you about the fact that this contains 1024 lines of code, it is so hard to transfer variables between classes, let alone scripts...
    If you need the info, I am trying to make a game where you are a cpu manufacturer and you sell cpus. like a tycoon game.

    Thanks for helping (if you did)!


    EDIT:
    I fixed it!
    How:
    Unity for some reason doesnt accept the version of switch() is used that Visual Studio recommended me to use.

    WHAT I USED:

    Code (CSharp):
    1. transistorValue = transistorSizeExpString switch
    2.         {
    3.             "micro" => 0.000001 * transistorSize,
    4.             "nano" => 0.000000001 * transistorSize,
    5.             "pico" => 0.000000000001 * transistorSize,
    6.             _ => 0,
    7.         };
    WHAT UNITY ACCEPTS:

    Code (CSharp):
    1. switch (transistorSizeExpString)
    2.         {
    3.             case "micro":
    4.                 transistorValue = 0.000001 * transistorSize;
    5.                 break;
    6.             case "nano":
    7.                 transistorValue = 0.000000001 * transistorSize;
    8.                 break;
    9.             case "pico":
    10.                 transistorValue = 0.000000000001 * transistorSize;
    11.                 break;
    12.             default:
    13.                 break;
    14.         }
     
    Last edited: Jun 24, 2020
  2. ?

    No, it is not, you can learn it, don't give up on it! You will have more problems with your one big file game, believe me.
    Just wait until you can't open up your file for a week for some reason and see how much time you will spend on looking for things and trying to fix things.


    var otherScript = otherGameObject.GetComponent<WhateverScript>();
    [...]
    otherScript.Foo = "bar";
     
    PraetorBlue likes this.