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. Dismiss Notice

[GUI] - Check if an shop item are already bought.

Discussion in 'Scripting' started by qgouty, Apr 29, 2014.

  1. qgouty

    qgouty

    Joined:
    Jul 26, 2013
    Posts:
    8
    Hi everyone,

    Actually, I'm working on a GUI javascript for a shop. I want that if I bought an item, a message say like : "Congragulation. You have bought this item". And if I try to bought the same item again, a others message say like : You can't buy it. You have already bought it".

    I've souht a lot of methods, with booleans or others but it's not working.
    Please tell me if you have find a method for that.

    For clarification, I have a nearly 50 item to check

    Thanks for advance.

    P.S : I've don't put it to Unity Aswers. It has a bug for tags
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    How are you trying to do it at the moment? It depends on a lot of things, like how other parts of your game work.

    As a complete stab in the dark, you could make a MonoBehaviour called "PurchasedItemList" and attach it to your player(s). You can give it a List<...> of item IDs or item references or whatever you're using to define items in your shop. (You haven't told us, so can't really be more specific.) You then have public methods "AddItem", "RemoveItem" and "HasItem" which map directly to available methods on the List<...>. Then, when the player tries to purchase something from the shop, you first call HasItem(theItem) to see if the player has already got it. If they do not, then you call AddItem(theItem) when the purchase is confirmed. If an item can ever get un-purchased or lost or consumed or whatever then you can also call RemoveItem(theItem).

    Also, it doesn't sound like it's a bug, which might put people off giving you an answer at the Answers site.
     
  3. qgouty

    qgouty

    Joined:
    Jul 26, 2013
    Posts:
    8
    Hi angrypenguin,
    I create an online game.

    Here is the method that I use currently :

    Code (csharp):
    1. #pragma strict
    2.  
    3. var guiSkin : GUISkin;
    4.  
    5. var datas : int;
    6.  
    7. var showCanonOptions : boolean;
    8. var showShieldOtpions : boolean;
    9. var showCPUOptions : boolean;
    10. var showSoftwareOptions : boolean;
    11.  
    12. var scrollPositionCanon : Vector2 = Vector2.zero;
    13. var scrollPositionShield : Vector2 = Vector2.zero;
    14. var scrollPositionCPU : Vector2 = Vector2.zero;
    15. var scrollPositionSoftware : Vector2 = Vector2.zero;
    16.  
    17.  
    18. private var currentItemInfo : String;
    19.  
    20. var defaultItemInfo : String = "Click a button to show correspondant features";
    21. var canonIonInfo = "It's the default canon, it's free, but not very powerful. Standard Shot properties. No Datas required.";
    22. var canonProtonInfo = "This canon is low cost. A little more powerful than the ion canon, the proton canon afflict more dammage. Datas required : 10 To";
    23. var canonNeutronInfo = "The neutron is a neutral electric particle. This canon can afflict dammage on all shield. However, the dammage are not very important. Datas required : 20 To";
    24. var canonNeutrinoInfo = "Exactly as the neutron canon, but better. Datas required : 40 To";
    25. var canonPhotonInfo = "The photon contain a lot of energy. But unfortunatly, it's used to dazzling the ennemies, cause, if it's used for explosions, the canon are directly atomized. Datas required : 80 To";
    26. var canonPositronInfo = "The positron is the inverse of the electron, so it's a positive intense electric particle. On collision, it create a good range of dammage. Datas required : 160 To";
    27. var canonMuonInfo = "This canon offer a big ball, with a incredible contact radius. Datas required : 320 To";
    28. var canonTuaonInfo = "The tuaon canon eject a little ball but very fastly. Datas required : 640 To";
    29. var canonAxionInfo = "Axion is a particle very long. So the ball ejected will be long too. Better contact zone on the width. Datas required : 1280 To.";
    30. var canonPionsInfo = "The pions canon launch a lot of a little bit balls, with an awsome dammage. Datas required : 2560 To";
    31. var canonGravitonInfo = "The graviton is the particle of the gravity. The contact explosion is in fact an implosion, but after few seconds, a big explosion. Datas required : 5120 To";
    32. var canonQuarkInfo = "The quark is the composite of all particles. So the energy delivered is breath taking ! Datas required : 6240 To";
    33. var canonTetraquarkInfo = "More powerful than the quark. Is the composite of the quark... Datas required : 8360 To";
    34. var canonPentaquarkInfo = "The composite of the composite of the composite of every particles. Datas required : 10390 To";
    35. var canonLeptoquarkInfo = "A pentaquark can't exist whitout leptoquarks. Datas required : 12900 To";
    36. var canonHyperonInfo = "A scientific experience create a new hyper nuclear particle : the hyperon. Datas required : 15000 To";
    37. var canonPiomiumInfo = "The most energetic particle. When it's broke, it send the same enrgy that the gamma ray burst ! Datas required : 25000 To";
    38.  
    39. var shieldIronInfo = "The most used material for shield. Free and not very resistant. No datas required.";
    40. var shieldSteelInfo = "A not very expensive and durable material. Datas required : 20 To";
    41. var shieldAluminiumInfo = "The aluminium is more lightweight than the steel. Datas required : 40 To";
    42. var shieldGalliumInfo = "The gallium element is studed to be more resistant to the corrosion. Datas required : 80 To";
    43. var shieldZirconiumInfo = "The evolution of the gallium. Datas required : 160 To";
    44. var shieldPooloniumInfo = "The poolonium is the pooling of the galluim and the zirconium with more features. Datas required : 320 To";
    45. var shieldThalliumInfo = "Have the same resistance of the diamond. Datas required : 640 To";
    46. var shieldIndiumInfo = "A metal discovered in the India, very expensive, but absorb all chocs. So it's quasi unvunerable. Datas required : 1280 To";
    47. var shieldVanadiumInfo = "One thing to say : more solid that the diamond. Datas required : 2560 To";
    48. var shieldYttriumInfo = "Hard to machinning. A little radioactive... Datas required : 5120 To";
    49. var shieldRodhiumInfo = "A extremely radioactive metal. Datas required : 10240 To";
    50. var shieldIridiumInfo = "Discovered on a meteor. Must be heated to billions degres and subject to radioactivity at the same time to be breaked. Datas required : 20480 To";
    51.  
    52. var CPUXtronT7Info = "More effective than the default CPU. Datas required : 1000 To";
    53. var CPUXtronFG8Info = "A better version of the Xtron T7 CPU. Datas required : 2000 To";
    54. var CPUTauonBInfo = "Name inspired by the particle. This CPU is more faslty that the precedents. Datas required : 4000 To";
    55. var CPUPoTetraKInfo = "The PoTetra-K CPU is 3 times more powerfull than the Tauon-B controller. Datas required : 8000 To";
    56. var CPUProShot30Info = "As its name suggests, it give more precision. Datas required : 16000 To";
    57. var CPUXetronFRGInfo = "A french high-quality CPU. Datas required : 32000 To";
    58. var CPUTXSLInfo = "It's a very good controller. More powerful and fast, it's the better in the market. Datas required : 64000 To";
    59. var CPUTXMAInfo = "A version revised of the TX-SL. Datas required : 128000 To";
    60. var CPUMAEERADIXInfo = "A CPU built fo eradicate others robot. Datas required : 256000 To";
    61. var CPUProtonix60Info = "A prototype of a CPU never built. But however very interesting. Datas required : 512000 To";
    62. var CPUNeutroxInfo = "Basically, it was created with a cerebral control, but the machine take the control too easly... Datas required : 1240000 To";
    63. var CPUDytriumInfo = "A controller based of an 'intelligent' particle : the dytrium. It have more cache memory than hard drive memory. Data required : 2000000 To";
    64.  
    65. var SoftwareCanopyInfo = "A program used for spacial operations. Datas required : 1500 To";
    66. var SoftwareCuna12Info = "A software created for gouvernment investigations. Datas required : 3000 To";
    67. var SoftwareIncome39Info = "Impossible to store it to a supercomputer. Datas required : 6000 To";
    68. var SoftwareCanoe76Info = "Better than the human cortex for certains things... Datas required : 12000 To";
    69. var SoftwareUnmanInfo = "Not need humain, it's standalone. Datas required : 15000 To";
    70. var SoftwareAkanInfo = "Better tahn Unman. That is all you have to know. Datas required : 20000 To";
    71. var SoftwarePineInfo = "A very aggresive software. More than better informatic viruses. Datas required : 30000 To";
    72. var SoftwareGnonoxInfo = "The crusher of crushers... Datas required : 50000 To";
    73.  
    74.  
    75. var installCheckerInfo : String = "Install checking console";
    76. var errorCheckingInfo = "Installation error : Type IE-NEM-01. More datas needed";
    77. var oKCheckingInfo = "Sucsessfuly installed";
    78. var alreadyCheckInfo = "Already installed";
    79.  
    80. var currentPrice : int;
    81.  
    82. var canonIonPrice = 0;
    83. var canonProtonPrice = 10;
    84. var canonNeutronPrice = 20;
    85. var canonNeutrinoPrice = 40;
    86. var canonPhotonPrice = 80;
    87. var canonPositronPrice = 160;
    88. var canonMuonPrice = 320;
    89. var canonTauonPrice = 640;
    90. var canonAxionPrice = 1280;
    91. var canonPionsPrice = 2560;
    92. var canonGravitonPrice = 5120;
    93. var canonQuarkPrice = 6240;
    94. var canonTetraquarkPrice = 8360;
    95. var canonPentaquarkPrice = 10390;
    96. var canonLeptoquarkPrice = 12900;
    97. var canonHyperonPrice = 15000;
    98. var canonPiomiumPrice = 25000;
    99.  
    100. var shieldIronPrice = 0;
    101. var shieldSteelPrice = 20;
    102. var shieldAluminiumPrice = 40;
    103. var shieldGalliumPrice = 80;
    104. var shieldZirconiumPrice = 160;
    105. var shieldPooloniumPrice = 320;
    106. var shieldThalluimPrice = 640;
    107. var shieldIndiumPrice = 1280;
    108. var shieldVanadiumPrice = 2560;
    109. var shieldYttriumPrice = 5120;
    110. var shieldRodhiumPrice = 10240;
    111. var shieldIridiumPrice = 20480;
    112.  
    113. var CPUXtronT7Price = 1000;
    114. var CPUXtronFG8Price = 2000;
    115. var CPUTauonBPrice = 4000;
    116. var CPUPoTetraKPrice = 8000;
    117. var CPUProshot30Price = 16000;
    118. var CPUXetronFRGPrice = 32000;
    119. var CPUTXSLPrice = 64000;
    120. var CPUTXMAPrice = 128000;
    121. var CPUMAERADIXPrice = 256000;
    122. var CPUProtonix60Price = 512000;
    123. var CPUNeutroxPrice = 1240000;
    124. var CPUDYtriumPrice = 2000000;
    125.  
    126. var SoftwareCanopyPrice = 1500;
    127. var SoftwareCuna12Price = 3000;
    128. var SoftwareIncome39Price = 6000;
    129. var SoftwareCanoe76Price = 12000;
    130. var SoftwareUnmanPrice = 15000;
    131. var SoftwareAkanPrice = 20000;
    132. var SoftwarePinePrice = 30000;
    133. var SoftwareGnonoxPrice = 50000;
    134.  
    135.  
    136. var canonIonCheck = false;
    137. var canonProtonCheck = false;
    138. var canonNeutronCheck = false;
    139. var canonNeutrinoCheck = false;
    140. var canonPhotonCheck = false;
    141. var canonPositronCheck = false;
    142. var canonMuonCheck = false;
    143. var canonTauonCheck = false;
    144. var canonAxionCheck = false;
    145. var canonPionsCheck = false;
    146. var canonGravitonCheck = false;
    147. var canonQuarkCheck = false;
    148. var canonTetraquarkCheck = false;
    149. var canonPentaquarkCheck = false;
    150. var canonLeptoquarkCheck = false;
    151. var canonHyperonCheck = false;
    152. var canonPiomiumCheck = false;
    153.  
    154. var shieldIronCheck = false;
    155. var shieldSteelCheck = false;
    156. var shieldAluminiumCheck = false;
    157. var shieldGalliumCheck = false;
    158. var shieldZirconiumCheck = false;
    159. var shieldPooloniumCheck = false;
    160. var shieldThalluimCheck = false;
    161. var shieldIndiumCheck = false;
    162. var shieldVanadiumCheck = false;
    163. var shieldYttriumCheck = false;
    164. var shieldRodhiumCheck = false;
    165. var shieldIridiumCheck = false;
    166.  
    167. var CPUXtronT7Check = false;
    168. var CPUXtronFG8Check = false;
    169. var CPUTauonBCheck = false;
    170. var CPUPoTetraKCheck = false;
    171. var CPUProshot30Check = false;
    172. var CPUXetronFRGCheck = false;
    173. var CPUTXSLPriceCheck = false;
    174. var CPUTXMAPriceCheck = false;
    175. var CPUMAERADIXCheck = false;
    176. var CPUProtonix60Check = false;
    177. var CPUNeutroxCheck = false;
    178. var CPUDYtriumCheck = false;
    179.  
    180. var SoftwareCanopyCheck = false;
    181. var SoftwareCuna12Check = false;
    182. var SoftwareIncome39Check = false;
    183. var SoftwareCanoe76Check = false;
    184. var SoftwareUnmanCheck = false;
    185. var SoftwareAkanCheck = false;
    186. var SoftwarePineCheck = false;
    187. var SoftwareGnonoxCheck = false;
    188.  
    189.  
    190. function Start () {
    191.  
    192.     showCanonOptions = false;
    193.     showShieldOtpions = false;
    194.     showCPUOptions = false;
    195.     showSoftwareOptions = false;
    196.    
    197.     currentItemInfo = defaultItemInfo;
    198.    
    199.     currentPrice = 0;
    200.    
    201.     canonIonCheck = false;
    202.     canonProtonCheck = false;
    203.     canonNeutronCheck = false;
    204.     canonNeutrinoCheck = false;
    205.     canonPhotonCheck = false;
    206.     canonPositronCheck = false;
    207.     canonMuonCheck = false;
    208.     canonTauonCheck = false;
    209.     canonAxionCheck = false;
    210.     canonPionsCheck = false;
    211.     canonGravitonCheck = false;
    212.     canonQuarkCheck = false;
    213.     canonTetraquarkCheck = false;
    214.     canonPentaquarkCheck = false;
    215.     canonLeptoquarkCheck = false;
    216.     canonHyperonCheck = false;
    217.     canonPiomiumCheck = false;
    218.  
    219.     shieldIronCheck = false;
    220.     shieldSteelCheck = false;
    221.     shieldAluminiumCheck = false;
    222.     shieldGalliumCheck = false;
    223.     shieldZirconiumCheck = false;
    224.     shieldPooloniumCheck = false;
    225.     shieldThalluimCheck = false;
    226.     shieldIndiumCheck = false;
    227.     shieldVanadiumCheck = false;
    228.     shieldYttriumCheck = false;
    229.     shieldRodhiumCheck = false;
    230.     shieldIridiumCheck = false;
    231.    
    232.     CPUXtronT7Check = false;
    233.     CPUXtronFG8Check = false;
    234.     CPUTauonBCheck = false;
    235.     CPUPoTetraKCheck = false;
    236.     CPUProshot30Check = false;
    237.     CPUXetronFRGCheck = false;
    238.     CPUTXSLPriceCheck = false;
    239.     CPUTXMAPriceCheck = false;
    240.     CPUMAERADIXCheck = false;
    241.     CPUProtonix60Check = false;
    242.     CPUNeutroxCheck = false;
    243.     CPUDYtriumCheck = false;
    244.  
    245.     SoftwareCanopyCheck = false;
    246.     SoftwareCuna12Check = false;
    247.     SoftwareIncome39Check = false;
    248.     SoftwareCanoe76Check = false;
    249.     SoftwareUnmanCheck = false;
    250.     SoftwareAkanCheck = false;
    251.     SoftwarePineCheck = false;
    252.     SoftwareGnonoxCheck = false;
    253.  
    254. }
    255.  
    256. function OnGUI () {
    257.  
    258.     GUI.skin = guiSkin;
    259.  
    260.     if (GUI.Button (Rect (0,Screen.height - 410,100,50), "Canons")) {
    261.    
    262.         showCanonOptions = !showCanonOptions;
    263.     }
    264.    
    265.     if (showCanonOptions) {
    266.    
    267.         scrollPositionCanon = GUI.BeginScrollView (Rect (100,Screen.height - 410,Screen.width - 100,65), scrollPositionCanon, Rect(100, Screen.height - 410, 1870, 40));
    268.        
    269.             if (GUI.Button (Rect (100,Screen.height - 410,100,50), "Ion")) {
    270.            
    271.                 currentItemInfo = canonIonInfo;
    272.                 currentPrice = canonIonPrice;
    273.            
    274.             }
    275.             if (GUI.Button (Rect (200,Screen.height - 410,100,50), "Proton")) {
    276.            
    277.                 currentItemInfo = canonProtonInfo;
    278.                 currentPrice = canonProtonPrice;
    279.            
    280.             }
    281.             if (GUI.Button (Rect (300,Screen.height - 410,100,50), "Neutron")) {
    282.            
    283.                 currentItemInfo = canonNeutronInfo;
    284.                 currentPrice = canonNeutronPrice;
    285.            
    286.             }
    287.             if (GUI.Button (Rect (400,Screen.height - 410,100,50), "Neutrino")) {
    288.            
    289.                 currentItemInfo = canonNeutrinoInfo;
    290.                 currentPrice = canonNeutrinoPrice;
    291.            
    292.             }
    293.             if (GUI.Button (Rect (500,Screen.height - 410,100,50), "Photon")) {
    294.            
    295.                 currentItemInfo = canonPhotonInfo;
    296.                 currentPrice = canonPhotonPrice;
    297.                
    298.             }
    299.             if (GUI.Button (Rect (600,Screen.height - 410,100,50), "Positron")) {
    300.            
    301.                 currentItemInfo = canonPositronInfo;
    302.                 currentPrice = canonPositronPrice;
    303.            
    304.             }
    305.             if (GUI.Button (Rect (700,Screen.height - 410,100,50), "Muon")) {
    306.            
    307.                 currentItemInfo = canonMuonInfo;
    308.                 currentPrice = canonMuonPrice;
    309.            
    310.             }
    311.             if (GUI.Button (Rect (800,Screen.height - 410,100,50), "Tuaon")) {
    312.            
    313.                 currentItemInfo = canonTuaonInfo;
    314.                 currentPrice = canonTauonPrice;
    315.            
    316.             }
    317.             if (GUI.Button (Rect (900,Screen.height - 410,100,50), "Axion")) {
    318.            
    319.                 currentItemInfo = canonAxionInfo;
    320.                 currentPrice = canonAxionPrice;
    321.            
    322.             }
    323.             if (GUI.Button (Rect (1000,Screen.height - 410,100,50), "Pions")) {
    324.            
    325.                 currentItemInfo = canonPionsInfo;
    326.                 currentPrice = canonPionsPrice;
    327.            
    328.             }
    329.             if (GUI.Button (Rect (1100,Screen.height - 410,100,50), "Graviton")) {
    330.            
    331.                 currentItemInfo = canonGravitonInfo;
    332.                 currentPrice = canonGravitonPrice;
    333.            
    334.             }
    335.             if (GUI.Button (Rect (1200,Screen.height - 410,100,50), "Quark")) {
    336.            
    337.                 currentItemInfo = canonQuarkInfo;
    338.                 currentPrice = canonQuarkPrice;
    339.            
    340.             }
    341.             if (GUI.Button (Rect (1300,Screen.height - 410,100,50), "Tetraquark")) {
    342.            
    343.                 currentItemInfo = canonTetraquarkInfo;
    344.                 currentPrice = canonTetraquarkPrice;
    345.            
    346.             }
    347.             if (GUI.Button (Rect (1400,Screen.height - 410,100,50), "Pentaquark")) {
    348.            
    349.                 currentItemInfo = canonPentaquarkInfo;
    350.                 currentPrice = canonPentaquarkPrice;
    351.            
    352.             }
    353.             if (GUI.Button (Rect (1500,Screen.height - 410,100,50), "Leptoquark")) {
    354.            
    355.                 currentItemInfo = canonLeptoquarkInfo;
    356.                 currentPrice = canonLeptoquarkPrice;
    357.            
    358.             }
    359.             if (GUI.Button (Rect (1600,Screen.height - 410,100,50), "Hyperon")) {
    360.            
    361.                 currentItemInfo = canonHyperonInfo;
    362.                 currentPrice = canonHyperonPrice;
    363.            
    364.             }
    365.             if (GUI.Button (Rect (1700,Screen.height - 410,100,50), "Piomium")) {
    366.            
    367.                 currentItemInfo = canonPiomiumInfo;
    368.                 currentPrice = canonPiomiumPrice;
    369.            
    370.             }
    371.         GUI.Box (Rect (1780,Screen.height - 410,200,50), "More - Comming soon");
    372.        
    373.         GUI.EndScrollView();
    374.     }
    375.    
    376.     if (GUI.Button (Rect (0,Screen.height - 200,100,50), "Shield")) {
    377.    
    378.         showShieldOtpions = !showShieldOtpions;
    379.     }
    380.    
    381.     if (showShieldOtpions) {
    382.    
    383.         scrollPositionShield =  GUI.BeginScrollView (Rect (100,Screen.height - 200,Screen.width - 100,65), scrollPositionShield, Rect(100, Screen.height - 200, 1200, 40));
    384.             if (GUI.Button (Rect (100,Screen.height - 200,100,50), "Iron")) {
    385.            
    386.                 currentItemInfo = shieldIronInfo;
    387.                 currentPrice = shieldIronPrice;
    388.            
    389.             }
    390.             if (GUI.Button (Rect (200,Screen.height - 200,100,50), "Steel")) {
    391.            
    392.                 currentItemInfo = shieldSteelInfo;
    393.                 currentPrice = shieldSteelPrice;
    394.            
    395.             }
    396.             if (GUI.Button (Rect (300,Screen.height - 200,100,50), "Aluminium")) {
    397.            
    398.                  currentItemInfo = shieldAluminiumInfo;
    399.                  currentPrice = shieldAluminiumPrice;
    400.            
    401.             }
    402.             if (GUI.Button (Rect (400,Screen.height - 200,100,50), "Gallium")) {
    403.            
    404.                 currentItemInfo = shieldGalliumInfo;
    405.                 currentPrice = shieldGalliumPrice;
    406.            
    407.             }
    408.             if (GUI.Button (Rect (500,Screen.height - 200,100,50), "Zirconium")) {
    409.            
    410.                 currentItemInfo = shieldZirconiumInfo;
    411.                 currentPrice = shieldZirconiumPrice;
    412.            
    413.             }
    414.             if (GUI.Button (Rect (600,Screen.height - 200,100,50), "Poolonium")) {
    415.            
    416.                 currentItemInfo = shieldPooloniumInfo;
    417.                 currentPrice = shieldPooloniumPrice;
    418.            
    419.             }
    420.             if (GUI.Button (Rect (700,Screen.height - 200,100,50), "Thallium")) {
    421.            
    422.                 currentItemInfo = shieldThalliumInfo;
    423.                 currentPrice = shieldThalluimPrice;
    424.            
    425.             }
    426.             if (GUI.Button (Rect (800,Screen.height - 200,100,50), "Indium")) {
    427.            
    428.                 currentItemInfo = shieldIndiumInfo;
    429.                 currentPrice = shieldIndiumPrice;
    430.            
    431.             }
    432.             if (GUI.Button (Rect (900,Screen.height - 200,100,50), "Vanadium")) {
    433.            
    434.                 currentItemInfo = shieldVanadiumInfo;
    435.                 currentPrice = shieldVanadiumPrice;
    436.            
    437.             }
    438.             if (GUI.Button (Rect (1000,Screen.height - 200,100,50), "Yttrium")) {
    439.            
    440.                 currentItemInfo = shieldYttriumInfo;
    441.                 currentPrice = shieldYttriumPrice;
    442.            
    443.             }
    444.             if (GUI.Button (Rect (1100,Screen.height - 200,100,50), "Rhodium")) {
    445.            
    446.                 currentItemInfo = shieldRodhiumInfo;
    447.                 currentPrice = shieldRodhiumPrice;
    448.            
    449.             }
    450.             if (GUI.Button (Rect (1200,Screen.height - 200,100,50), "Iridium")) {
    451.            
    452.                 currentItemInfo = shieldIridiumInfo;
    453.                 currentPrice = shieldIridiumPrice;
    454.            
    455.             }
    456.        
    457.         GUI.EndScrollView();
    458.     }
    459.    
    460.     if (GUI.Button (Rect (0,Screen.height - 270,100,50), "CPU")) {
    461.    
    462.         showCPUOptions = !showCPUOptions;
    463.     }
    464.    
    465.     if (showCPUOptions) {
    466.    
    467.         scrollPositionCPU =  GUI.BeginScrollView (Rect (100,Screen.height - 270,Screen.width - 100,65), scrollPositionCPU, Rect(100, Screen.height - 270, 1200, 40));
    468.             if (GUI.Button (Rect (100,Screen.height - 270,100,50), "Xtron T7")) {
    469.            
    470.                 currentItemInfo = CPUXtronT7Info;
    471.                 currentPrice = CPUXtronT7Price;
    472.            
    473.             }
    474.             if (GUI.Button (Rect (200,Screen.height - 270,100,50), "Xtron FG8")) {
    475.            
    476.                 currentItemInfo = CPUXtronFG8Info;
    477.                 currentPrice = CPUXtronFG8Price;
    478.            
    479.             }
    480.             if (GUI.Button (Rect (300,Screen.height - 270,100,50), "Tauon B")) {
    481.            
    482.                 currentItemInfo = CPUTauonBInfo;
    483.                 currentPrice = CPUTauonBPrice;
    484.            
    485.             }
    486.             if (GUI.Button (Rect (400,Screen.height - 270,100,50), "PoTetra K")) {
    487.            
    488.                 currentItemInfo = CPUPoTetraKInfo;
    489.                 currentPrice = CPUPoTetraKPrice;
    490.            
    491.             }
    492.             if (GUI.Button (Rect (500,Screen.height - 270,100,50), "ProShot 30")) {
    493.            
    494.                 currentItemInfo = CPUProShot30Info;
    495.                 currentPrice = CPUProshot30Price;
    496.            
    497.             }
    498.             if (GUI.Button (Rect (600,Screen.height - 270,100,50), "Xetron FRG")) {
    499.            
    500.                 currentItemInfo = CPUXetronFRGInfo;
    501.                 currentPrice = CPUXetronFRGPrice;
    502.            
    503.             }
    504.             if (GUI.Button (Rect (700,Screen.height - 270,100,50), "TX SL")) {
    505.            
    506.                 currentItemInfo = CPUTXSLInfo;
    507.                 currentPrice = CPUTXSLPrice;
    508.            
    509.             }
    510.             if (GUI.Button (Rect (800,Screen.height - 270,100,50), "TX MA")) {
    511.            
    512.                 currentItemInfo = CPUTXMAInfo;
    513.                 currentPrice = CPUTXMAPrice;
    514.            
    515.             }
    516.             if (GUI.Button (Rect (900,Screen.height - 270,100,50), "MAE-ERADIX")) {
    517.            
    518.                 currentItemInfo = CPUMAEERADIXInfo;
    519.                 currentPrice = CPUMAERADIXPrice;
    520.            
    521.             }
    522.             if (GUI.Button (Rect (1000,Screen.height - 270,100,50), "Protonix 60")) {
    523.            
    524.                 currentItemInfo = CPUProtonix60Info;
    525.                 currentPrice = CPUProtonix60Price;
    526.            
    527.             }
    528.             if (GUI.Button (Rect (1100,Screen.height - 270,100,50), "Neutrox")) {
    529.            
    530.                 currentItemInfo = CPUNeutroxInfo;
    531.                 currentPrice = CPUNeutroxPrice;
    532.            
    533.             }
    534.             if (GUI.Button (Rect (1200,Screen.height - 270,100,50), "Dytrium")) {
    535.            
    536.                 currentItemInfo = CPUDytriumInfo;
    537.                 currentPrice = CPUDYtriumPrice;
    538.            
    539.             }
    540.        
    541.         GUI.EndScrollView();
    542.     }
    543.    
    544.         if (GUI.Button (Rect (0,Screen.height - 340,100,50), "Software")) {
    545.    
    546.         showSoftwareOptions = !showSoftwareOptions;
    547.     }
    548.    
    549.     if (showSoftwareOptions) {
    550.    
    551.         scrollPositionSoftware =  GUI.BeginScrollView (Rect (100,Screen.height - 340,Screen.width - 100,65), scrollPositionSoftware, Rect(100, Screen.height - 340, 800, 40));
    552.             if (GUI.Button (Rect (100,Screen.height - 340,100,50), "Canopy")) {
    553.            
    554.                 currentItemInfo = SoftwareCanopyInfo;
    555.                 currentPrice = SoftwareCanopyPrice;
    556.            
    557.             }
    558.             if (GUI.Button (Rect (200,Screen.height - 340,100,50), "Cuna 1.2")) {
    559.            
    560.                 currentItemInfo = SoftwareCuna12Info;
    561.                 currentPrice = SoftwareCuna12Price;
    562.            
    563.             }
    564.             if (GUI.Button (Rect (300,Screen.height - 340,100,50), "Income 3.9")) {
    565.            
    566.                 currentItemInfo = SoftwareIncome39Info;
    567.                 currentPrice = SoftwareIncome39Price;
    568.            
    569.             }
    570.             if (GUI.Button (Rect (400,Screen.height - 340,100,50), "Canoe 7.6")) {
    571.            
    572.                 currentItemInfo = SoftwareCanoe76Info;
    573.                 currentPrice = SoftwareCanoe76Price;
    574.            
    575.             }
    576.             if (GUI.Button (Rect (500,Screen.height - 340,100,50), "Unman")) {
    577.            
    578.                 currentItemInfo = SoftwareUnmanInfo;
    579.                 currentPrice = SoftwareUnmanPrice;
    580.            
    581.             }
    582.             if (GUI.Button (Rect (600,Screen.height - 340,100,50), "Akan")) {
    583.            
    584.                 currentItemInfo = SoftwareAkanInfo;
    585.                 currentPrice = SoftwareAkanPrice;
    586.            
    587.             }
    588.             if (GUI.Button (Rect (700,Screen.height - 340,100,50), "Pine")) {
    589.            
    590.                 currentItemInfo = SoftwarePineInfo;
    591.                 currentPrice = SoftwarePinePrice;
    592.            
    593.             }
    594.             if (GUI.Button (Rect (800,Screen.height - 340,100,50), "Gnonox")) {
    595.            
    596.                 currentItemInfo = SoftwareGnonoxInfo;
    597.                 currentPrice = SoftwareGnonoxPrice;
    598.            
    599.             }
    600.        
    601.         GUI.EndScrollView();
    602.     }
    603.    
    604.     var itemInfos = GUI.TextArea (Rect (0, Screen.height - 100, Screen.width - 0, 50), currentItemInfo);
    605.     var installChecker = GUI.TextArea (Rect (0, Screen.height - 130, Screen.width - 0, 30), installCheckerInfo);
    606.     GUI.Box (Rect (0, 0, Screen.width - 0, 50), "Datas : " + datas + " To");
    607.    
    608.     if (GUI.Button(Rect (0, Screen.height - 50, Screen.width - 0, 50), "Install using " + currentPrice + " To")) {
    609.    
    610.         if (datas < currentPrice) {
    611.        
    612.             installCheckerInfo = errorCheckingInfo;
    613.         }
    614.        
    615.         if (datas >= currentPrice) {
    616.            
    617.             installCheckerInfo = oKCheckingInfo;
    618.             datas = datas - currentPrice;
    619.         }
    620.    
    621.     }
    622. }
    I don't understand "AddItem", RemoveItem" ect.. can you exlain please ?
    Thanks for advance
     
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Hmm.

    Please don't take this the wrong way... After seeing the above code, I strongly suggest learning some more about programming before carrying on with this task. Learn about arrays, collections, classes and functions as a minimum, and this task will suddenly seem far easier.

    Generally speaking when programming, if you find yourself writing out lots and lots of similar stuff by hand then you're not using the right tool for the job somewhere. In this case you're only using one or two really basic tools, and you're trying to use them to do tasks with brute force that other tools (the 4 things I mentioned above) could achieve far more easily, in a more robust, easy to maintain manner.

    If the above is a challenge then expanding out to an entire online game is going to be nearly impossible.
     
  5. qgouty

    qgouty

    Joined:
    Jul 26, 2013
    Posts:
    8
    Thanks for yours advices, I'm learning about unity scripting. Sorry if I you're pissed, I don't understand what you said at your first post : I'm a french yong man...
    And, for class, i've already try. I don't know why unity does not take into account variables in class.

    For example, if I write somethig like :

    Code (csharp):
    1. class test extends System.Object (
    2.  
    3.       var var1 : String;
    4.       enum test (1,2,3);
    5.       var var2 : test;
    6. )
    7.  
    8. var Test : test;
    9.  
    10. function Update () (
    11.  
    12.   if (Test.var2.1) (
    13.  
    14.    print ("Something");
    15.   )
    16. )
    It doesn't work...
     
  6. Mukabr

    Mukabr

    Joined:
    Jun 10, 2013
    Posts:
    61
    Hey man, angrypenguin isn't pissed hehe, he's just trying to help you...
    About your code, he was referring to Lists, not Enums.

    Let me try helping you with this.

    First you need to import the right library for this
    Code (csharp):
    1. using System.Collections.Generic;
    and than, you need to initialise your List
    Code (csharp):
    1. public List<Item> ItemsBought = new List<Item>();
    and here, is the part where u should add the item every time you buy something
    Code (csharp):
    1. ItemsBought.Add(itemToBeBought);
    but... before buying the item, you should check the list to see if the player already have the item, so, it's something like this
    Code (csharp):
    1.  
    2. if(ItemsBought.Contains(itemToBeBought)){
    3.     //let the player know that he already have the item
    4. }else{
    5.     ItemsBought.Add(itemToBeBought);
    6. }
    well... i hope that helped you in some way

    Btw.... if you want to remove an item from the list:

    Code (csharp):
    1. ItemsBought.Remove(item)
    or if you want to remove by index
    Code (csharp):
    1. ItemsBought.RemoveAt(index)
     
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    I'm not pissed (or angry) at all. Just trying to point you towards a better path, that's all.

    The class you've got there isn't written correctly. Alas, my telling you how to correct it won't help you in the long run. You've got to learn and understand it for yourself. If you've got specific questions for your learning or are trying to solve a particular problem then the community here rocks and will help you out. You have to learn the basics for yourself though, that's not something we can give you piece by piece.

    Where are you learning from? Some resources are better than others, we might be able to help out by making sure you're using the better stuff. ;)
     
  8. qgouty

    qgouty

    Joined:
    Jul 26, 2013
    Posts:
    8
    Thanks for your advices angrypenguin and mukagbr. I precisely search it. If I don't understand what I write, it will be hard to develop my game....

    I'm looking for youtubes channels tutorials, but the betters are in english... If I don't understand all the persons say, i can't learn.

    Thanks again for advices and explications ( I didn't know that lists exist... I'm in the ignorance) .:confused:

    Just a final question : Are we obliged to write hooks for "if" and "else", because I noticed that some people do it, in C# ?

    Thanks again, I am very grateful to you. Good developping, teaching, or wahtever you do...
     
  9. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    By "hooks" do you mean braces? These things?
    Code (csharp):
    1. {          }
    They define a new "scope" or "block" of code. When you write an "if" statement, if it evaluates to 'true' then the following block or statement is executed. This means that they're optional if you only need to control execution of a single statement, but they're a requirement if you want to control more than one.

    This...
    Code (csharp):
    1.  
    2. if (x > 0) x = x - 1;
    3.  
    ... is the same as ...
    Code (csharp):
    1.  
    2. if (x > 0)
    3.     x = x - 1;
    4.  
    ... is the same as
    Code (csharp):
    1.  
    2. if (x > 0) {
    3.     x = x - 1;
    4. }
    5.  
    However, this...
    Code (csharp):
    1.  
    2. if (x > 0)
    3.     x = x - 1;
    4. y = y + 1;
    5.  
    ... is different to this:
    Code (csharp):
    1.  
    2. if (x > 0) {
    3.     x = x - 1;
    4.     y = y + 1;
    5. }
    6.  
    Note the spacing, how the "y = y + 1" line is indented differently in the two examples. White space is ignored by the compiler, but it's really useful to us human beings when we keep it nice and organised like that because it helps us see at a glance how things execute. :)
     
  10. qgouty

    qgouty

    Joined:
    Jul 26, 2013
    Posts:
    8
    Thanks AngryPenguin, for your great answer, so if i understood, the brackets define just "if" statement limitations.

    Thanks for all

    P.S : sorry for my bad english and translation...