Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Don't miss out on the Unite LA Keynote for the latest information from Unity! Set a reminder!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. 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.

  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,693
    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"