Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

GUI.Button changes position every frame

Discussion in 'Immediate Mode GUI (IMGUI)' started by Crax, Jun 15, 2014.

  1. Crax

    Crax

    Joined:
    Apr 11, 2013
    Posts:
    13
    I wrote this script:

    http://pastebin.com/9ExRmSMH
    (Don't know why but if i try to copy and paste my script from monodevelop there, the text will be filled of chinese characters)

    The problem is the button i draw when the player picks an item will change position every frame...
    And i don't what's wrong....
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,937
    Which line in the code is the button that moves?

    What value is "slot.x" getting ?
     
  3. Crax

    Crax

    Joined:
    Apr 11, 2013
    Posts:
    13
    With slot.x and slot.y i mean a and b values that i use in the void Start() to add slots to the slot class
    and, the problem is that i don't know why the button moves...
     
  4. Crax

    Crax

    Joined:
    Apr 11, 2013
    Posts:
    13
    With a Debug.Log(); i noted that for the Item[i=0], slot.x and slot.y changes every iteration...

    Anyway, the button is
    if(GUI.Button(new Rect(slot.x, slot.y, 50, 50),GameManager.items.icon)){

    }