Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by DMCH · Feb 05, 2013 at 04:29 PM · guitexturestretching

Unable to stretch texture over entire button

Hello,

Having some difficulty getting a texture to stretch over an entire button. Have checked the other threads, but nothing has worked so far.

I'm building a GUI screen to allow players to buy weapons, and I want the weapon texture on the buttons. The texture fills the button vertically, but not horizontally.

This is how I'm loading the buttons. The texture comes from an array of objects

 if(unlocked == true)

{

         GUI.Button(new Rect(topButtonSpacing + weaponBoxWidth + (topButtonSpacing * (i+1)) + (weaponBoxWidth * i),
         (vertSpacing * 3) + topButtonHeight, 
         weaponBoxWidth,
         weaponBoxHeight), (Texture)tempMasterWeaponList[i].GetWeaponImage(), "stretchButton");}


stretchButton is a custom style in a GUI Skin. It has no border, fixed h/w are 0, stretch h/w are ticked.

Other things I've tried:

  1. Setting the texture type as a GUI.

  2. Creating a custom GUI Style for each button, with the desired texture as the background. This does actually stretch the texture properly, but it's an extremely unwieldly solution given that there are multiple states for each button, and a good number of weapons.

  3. Create the texture at exactly the same size as button. Almost, but doesn't stretch over whole button.

Can anyone help? Thanks a lot!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Thibaut D · Feb 07, 2013 at 02:26 PM

As far as I renember GUIButton with texture try to keep your original texture ratio. That's mean hat if your button as a different ratio, the button will not be totaly fill with the texture.

I Don't renember if you can do it by editing the GUI skin (On a skin look at "button" and try to check Stretch Width and stretch Height).

An other solution. A little crapy solution. Replace your button with a DrawTexture AND a BUTTON. DrawTexture by default stretch your texture to fill the rect entierly. For exemple :

 GUI.Button(MyRect, MyTexture);

 Can be replace with

 GUI.DrawTexture(MyRect, MyTexture);
 GUI.Button(MyRect, "");
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DMCH · Feb 07, 2013 at 02:47 PM 0
Share

Thanks for the help. Good to have another solution to the problem. At the moment I'm just using a lot of GUI Styles, which also stretches textures properly.

avatar image M_Plot · Jul 19, 2013 at 02:14 PM 0
Share

I tried that with GUI.Window ins$$anonymous$$d of button and it didnt work

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Stretching Texture2D 1 Answer

scaling behaviour of the standard box texture? 0 Answers

GUI texture size doesn't match control set with the same size 1 Answer

Touchscreen for unity 2 Answers

Display GUI texture on specific variable value? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges