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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

GUITexture: border parameters

Discussion in 'Editor & General Support' started by joker, Jul 30, 2007.

  1. joker

    joker

    Joined:
    Apr 4, 2007
    Posts:
    10
    How can I access by script the GUITexture border parameters (left border, top border....)?
    Thanks

    Antonio
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    It doesn't look like these variables are exposed to scripting. I recommend filing a bug report to get them exposed in a later version.
     
  3. joker

    joker

    Joined:
    Apr 4, 2007
    Posts:
    10
    I fear you're right. Now I'm really stuck as I have to model through a GUITexture a life bar drecreasing right to left. I will appreciate a word from OTEE guys: is there a workaround to achieve this?
    Thanks
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Can't you just set the borders and inset to zero, and use the transform scale?
     
  5. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    There are numerous ways to do life/health bars that don't require _scripted_ access to the border properties. Perhaps you can explain why lack of script access is a barrier and then we can advise on how to deal with that?

    FYI: I too find it odd that you can't access those properties and after chatting with Sam about it we'll file a bug about this (unless someone has already? if you have then please let me know the bug ID number - either here in this thread, via PM or email).
     
  6. joker

    joker

    Joined:
    Apr 4, 2007
    Posts:
    10
    Hello Higgy, thanks for your reply.
    We found out that buy using the border values in conjuction with pixel inset values you can achieve UV scaling on a GUITexture. Since we have to model a life bar, decreasing right to left as the player gets damaged, we've though this to be the ideal solution. We haven't filed any bug; will appreciate if you could do that. Cheers,

    Antonio
     
  7. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Not a problem Antonio, I'll handle logging a bug about this one. The question still remains though, do you need a workaround for something here? Sure you don't have scripted access to the border values, but you can manually set them in Unity and go from there. If you need various border values then perhaps you can make a prefab GUI Texture for your various border value combinations? Let us know if you need any help sorting out how to proceed given this limitation, otherwise we'll just assume you're off and running.

    Me? I'm off to log that bug now... :)
     
  8. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    I ran into the same problem today, but I have a workaround for my use, that only involves duplicating some info.

    Another way to solve Antonio's original task, a healthbar with texture decreasing from right to left, would be
    - model the healthbar as a plane in 3D
    - as the bar decreases:
    --- scale the size of the plane down, using e.g. transform.localScale
    --- scale the texture of the plane material up, using e.g. renderer.material.mainTextureScale
    --- there should be no need to manipulate the offset, but if necessary it could be done with renderer.material.mainTextureOffset
     
  9. nerophon

    nerophon

    Joined:
    Aug 8, 2009
    Posts:
    35
    Hey,

    Did this ever get done? I mean exposing the border properties to scripting?

    Was that bug ever posted?

    I could really use this feature right about now :)

    ADDENDUM:

    I filed a bug. Case 363854.

    FURTHER ADDENDUM:

    I have discovered that one can work around this issue by using code-generated gui elements with GUIStyles.
    Here's the procedure:

    1. Place desired image as the 'normal background' of the GUIStyle.
    2. Write a GUI.Label in a script's OnGUI function which uses the GUIStyle.
    3. Access the border properties of the GUIStyle as noted in the documentation.
    4. You will notice the desired effect on your image.

    I must note here that this is a workaround; the functionality should really be exposed in the GUITexture class. I can't imagine why this hasn't been fixed by now. It seems like a really simple thing to do, and in a lot of cases using GUITexture as a component is preferable to using OnGUI.

    In case anyone is interested in doing a standard health-bar type effect, the solution (using this method) is to set the 'width' and the 'left border' simultaneously to the same value, which of course should usually be:

    = health% * fullBarLength;
     
  10. Zogg

    Zogg

    Joined:
    Mar 28, 2009
    Posts:
    157
    @nerophon : Good trick, works great! Now I can finally implement a decent life bar! Thank you! You saved my life(bar)! I love you! Would you marry me?

    (Err, forget about the last two sentences. But still a great trick.)
     
  11. Kilah

    Kilah

    Joined:
    Oct 5, 2010
    Posts:
    23
    Has this issue ever been address? We just run into this problem, and even though there are work arounds, for those who prefer not to use GUI functionality would be a great improvement to have access to borders from a scripting point of view.

    Cheers.

    EDIT: Or having access to UV on GUITextures would be great too, but I guess that is a more complicated issue, as HiggyB already confirmed borders should be accessible.
     
  12. rudolfwm

    rudolfwm

    Joined:
    Apr 17, 2009
    Posts:
    11
    Did this ever get done? I just stumbled upon it too.

    A bit silly since this bug apparently exists since 2007
     
  13. jean

    jean

    Joined:
    Jan 14, 2011
    Posts:
    1
    @nerophon

    Thanks for the hint, nice work!
    I've tried to find a way to do that for days, and now it's done.
    It's sad that all of this has to be done for a simple task, on a robust Engine like Unity, but, it's done.
    I'm looking forward to see this bug solved.

    []'s
     
  14. mgebra

    mgebra

    Joined:
    Sep 22, 2010
    Posts:
    27
    I have same problem and can't use GUI.Label. Is there any other way to make progress bar with GUITexture? I guess this bug wont be fix :(
     
  15. CrazyEoin

    CrazyEoin

    Joined:
    May 1, 2009
    Posts:
    51
    Just chiming in here on this also. Such a simple little thing and its causing me no end of problems. I know there are work around solutions here but it would be so much easier to just expose the required varaibles as public. I dont want to use OnGUI because of the associated preformance hit, especially for the 1 or 2 words that I was planning to use in the Speach bubble i've created. Please fix this 4 year old bug!
     
  16. juan-jo

    juan-jo

    Joined:
    May 15, 2010
    Posts:
    162
    I'm on this too.
    I want to use GUITexture to do variable amount of miniatures and cut leftover by using width and border. Testing in editor worked well, but now I can't do it by code.
    Seems GUITexture is recommended way to do interface on iOS because of performance, but then is too limited (can't make a simple offset-atlas too…) :-?
     
    Last edited: Feb 2, 2012
  17. archivision

    archivision

    Joined:
    Jun 17, 2009
    Posts:
    91
    will this ever be fixed? i would like to acces this trough scripting.. because i create GUITextures in script. need the borders..
    just acces it trough "guiTexture.leftBorder" or something like that.. or a Rect. Good luck unity people with creating this ;)
    it is realy weird, that after 5 years of knowing this problem... that there's not a normal fix for this.
     
    Last edited: Feb 21, 2012
  18. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    416
    We're really sorry that we kept you waiting for such a long time. The properties are exposed now and will most likely be available in the next Unity release.

    Cheers!
     
  19. Mycroft Holmes

    Mycroft Holmes

    Joined:
    Aug 19, 2010
    Posts:
    31
    So when exactly is Unity 4.0 releasing since I'm hitting the same issue as the original 5yo post?
     
  20. zagahlo

    zagahlo

    Joined:
    Aug 5, 2012
    Posts:
    6
    I need too modify by scripting these borders properties...I will try nerophon workaround

    PD
    It has not been implemented yet on Unity 3.5.5f3
     
  21. Agent654

    Agent654

    Joined:
    Dec 11, 2012
    Posts:
    8
    Ok - so this appears to be an ANCIENT bug - and I have just ran up against this as well. I'm working in Unity 4.x and currently attempting to manipulate the border of a GUITexture. I've noticed there is now a GUITexture.border.Remove() function that accepts a Rect as an argument, but no matter what I feed it, I am unable to manipulate the border values of the Texture in question.

    Kuba, or any other Unity Developers - can we get a chunk of example code with this functional?
     
  22. Agent654

    Agent654

    Joined:
    Dec 11, 2012
    Posts:
    8
    So - for any of you wondering how to do this; after digging for a bit longer I was able to discover that the RectOffset class can actually accept direct parameters for left,right,top, bottom.

    I admit I feel very stupid having found this out for my first post - but figured I'd post a little chunk of code here that would help anyone else out that found themselves in this predicament. (In C#)

    Code (csharp):
    1. RectOffset tempOffset = new RectOffset(leftValue, rightValue, topValue, bottomValue);
    2. gameObject.GetComponent<GUITexture>().border = tempOffset;
    3.  
    This will effectively "set" your border for your GUITexture to your desired values.

    Apologies again for the 1st post - but the answer wasn't entirely clear at first.
     
    adham-dwikat likes this.
  23. adham-dwikat

    adham-dwikat

    Joined:
    Aug 17, 2013
    Posts:
    2

    thanks , that absolutely true and work for me ,this answer should be highlighted