Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Ints are getting doubled?

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

  1. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    186
    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:
    4,890
    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:
    186
    Yes debug.log is getting doubled too
     
  4. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    186
    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:
    186
    nvm i fixed it by changing a setting on my button in the function to "Off"