Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. The Burst compiler has its own forum section now.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted How to make upgrade multiplier for clicker game

Discussion in 'Scripting' started by ShovelingLife, Jul 27, 2020.

  1. ShovelingLife

    ShovelingLife

    Joined:
    Feb 4, 2020
    Posts:
    28
    Hello community I am making a clicker game but I don't know how to do the upgrade multiplier button such as Adventure Capitalist, I have a single script attached to each GameObject, total of six objects with the same script attached, where I have the Text object which shows a double value which is an array with six indexes, the problem here is that I have the multiplier button object attached with another script, I should do something as static (singleton) because each script has many objects, I only need to access to a single text which is upgrade price displayer crop which is non-static. Pls help me.
     

    Attached Files:

  2. speedyfast734

    speedyfast734

    Joined:
    Jun 21, 2015
    Posts:
    9
    Show the upgrade script so we know what your working with
     
  3. ShovelingLife

    ShovelingLife

    Joined:
    Feb 4, 2020
    Posts:
    28
    Hello speedy the code is, for upgrade

    Code (CSharp):
    1. public class MultiplyManager : MonoBehaviour
    2. {
    3.     public bool multiplier_Crop;
    4.  
    5.     public void multiply_Crop_PerOne()
    6.     {
    7.         UpgradeButtonCrop.multiplier = 1;
    8.     }
    9.     public void multiply_Crop_PerTen()
    10.     {
    11.         UpgradeButtonCrop.multiplier = 10;
    12.     }
    13.     public void multiply_Crop_PerHundred()
    14.     {
    15.         UpgradeButtonCrop.multiplier = 50;
    16.     }
    17. }
    18.  

    And for text object

    Code (CSharp):
    1.  
    2.  public static int multiplier = 1;
    3.  
    4. upgrade_price_displayer_crop.text = LargeNumber.ToString(crop_upgrade_price_arr[index]).ToString();
    5.  
    6. public void First_Crop_Button()
    7.     {
    8.         purchaseUpgradeCrop(0);
    9.     }
    10.     public void Second_Crop_Button()
    11.     {
    12.         purchaseUpgradeCrop(1);
    13.     }
    14.     public void Third_Crop_Button()
    15.     {
    16.         purchaseUpgradeCrop(2);
    17.     }
    18.     public void Fourth_Crop_Button()
    19.     {
    20.         purchaseUpgradeCrop(3);
    21.     }
    22.     public void Fifth_Crop_Button()
    23.     {
    24.         purchaseUpgradeCrop(4);
    25.     }
    26.     public void Last_Crop_Button()
    27.     {
    28.         purchaseUpgradeCrop(5);
    29.     }
    30.     public void purchaseUpgradeCrop(int index)
    31.     {
    32.         if ((level_crop_arr[index] + multiplier) <= max_level)
    33.         {
    34.                 if (DataController.Instance.gold >= crop_upgrade_price_arr[index] * multiplier)
    35.                 {
    36.                 updateUI_Crop(index);
    37.                 updateUpgrade_Crop();
    38.                     //updateUI_Crop();
    39.                 DataController.Instance.saveUpgradeButton_Crop(this);
    40.                 }
    41.             }
    42.         else
    43.         {
    44.             UpgradeMessageManager.instance.Start_coroutine_cant_upgrade();
    45.             return;
    46.         }
    47.     }
     
  4. speedyfast734

    speedyfast734

    Joined:
    Jun 21, 2015
    Posts:
    9
    1. C#
      [*]public class MultiplyManager : MonoBehaviour
      [*][LIST=1]
      [*]{
      [*] public bool multiplier_Crop;
      [*]

      [*] public void multiply_Crop_PerOne()
      [*] {
      [*] UpgradeButtonCrop.multiplier =+ 1;
      [*] }
      [*] public void multiply_Crop_PerTen()
      [*] {
      [*] UpgradeButtonCrop.multiplier =+ 10;
      [*] }
      [*] public void multiply_Crop_PerHundred()
      [*] {
      [*] UpgradeButtonCrop.multiplier =+ 50;
      [*] }
      [*]}
      [/LIST]
      [*]
     
  5. speedyfast734

    speedyfast734

    Joined:
    Jun 21, 2015
    Posts:
    9
    I tried to put it in code format but Dont know how haha
     
  6. ShovelingLife

    ShovelingLife

    Joined:
    Feb 4, 2020
    Posts:
    28
    haha thanks for reply, the main problem that I am having is I need to show the multiplied price of the upgrade, so to do that I need to use a static function from the upgrade class, but the text object is non-static and to do that I should need change all of my code to static field, what could be the best way to do this? Update function just doesn't work with this coz the price need to be upgraded for each click and shown again.
     
  7. speedyfast734

    speedyfast734

    Joined:
    Jun 21, 2015
    Posts:
    9
    have u got
    using unity.text.ui;
    ?
     
  8. speedyfast734

    speedyfast734

    Joined:
    Jun 21, 2015
    Posts:
    9
  9. ShovelingLife

    ShovelingLife

    Joined:
    Feb 4, 2020
    Posts:
    28
    yes, sorry buddy, what I want to do is a upgrade multiplier
    for example total of 30 levels of an upgrade, if you click the button Buy, it shows x1, x10,
    if an upgrade costs 1, and you multiply it for 10 it will cost 10 and the level of the upgrade will increase 10 levels.

     
  10. speedyfast734

    speedyfast734

    Joined:
    Jun 21, 2015
    Posts:
    9
    OHHHHH I get u know
     
  11. speedyfast734

    speedyfast734

    Joined:
    Jun 21, 2015
    Posts:
    9
  12. ShovelingLife

    ShovelingLife

    Joined:
    Feb 4, 2020
    Posts:
    28
unityunity