Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Ints are getting doubled?

Discussion in 'Scripting' started by Vexer, Aug 13, 2018 at 8:45 AM.

  1. Vexer

    Vexer

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

    Vexer

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