Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Ints are getting doubled?

Discussion in 'Scripting' started by Vexer, Aug 13, 2018.

  1. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    187
    Hey Unity!

    For some reason all my ints are getting doubled any idea why?

    *For example my health potions should be upped by 1 but they get upped by 2(Same with my gold it should be upped by a number between 5 and 25 and it picks a number between 5 and 25 but then for some reason multiplies it...*

    Code (csharp):
    1.  
    2. void Start(){
    3. Slot2.onClick.AddListener(CollectHealthPotions);
    4. }
    5.  
    6. public void CollectHealthPotions()
    7.     {
    8.         Slot2Active = false; //This is a bool!
    9.         inventorymanager.HealthPotions += 1;
    10.         Debug.Log("Collected Loot!!");
    11.         //Destroy(GameObject.FindWithTag("LootSlot2"));
    12.         slot2.SetActive(false);
    13.     }
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,117
    Maybe the script is attached more than once somewhere in scene?
    Does it print that debug log once or twice? (note that you might have console window Collapse enabled)
     
  3. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    187
    Yes debug.log is getting doubled too
     
  4. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    187
    And i can't find a script being attached to two different objects or twice to one..
     
  5. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    187
    nvm i fixed it by changing a setting on my button in the function to "Off"