• 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 LSnake2001 · Sep 07, 2010 at 07:32 AM · gui

How can I have just a texture as a button?

Hi,

I would like to make a texture act as a button but can't seem to remove the dark, semi-transparent rectangle underneath it? I get the feeling this is really simple that I'm overlooking?

Here's my script;

(GUI.Button(Rect((Screen.width/2)-25,Screen.height-30,50,25), back_button)

Thanks.

Comment
Add comment · Show 2
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 · Sep 07, 2010 at 07:40 AM 0
Share

Dupe of http://answers.unity3d.com/questions/19982/how-can-i-have-just-a-texture-as-a-button (assu$$anonymous$$g double submit)

avatar image qJake · Sep 07, 2010 at 10:12 AM 0
Share

Don't mark both questions as duplicates. The other one no longer exists, and now this question still has comments and tags for duplicates.

3 Replies

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

Answer by qJake · Sep 07, 2010 at 10:15 AM

You need to create a custom GUIskin in order to remove the default one that Unity uses for buttons. Once you apply your custom skin, Unity's default button appearance should go away. If it doesn't, just go into your custom GUIskin and change the "Button" style's background texture to be transparent.

http://unity3d.com/support/documentation/Components/gui-Customization.html

If you don't want the default Unity style, you should really look into creating your own GUIskin, however. It's a lot easier and more flexible than simply using textures for everything.

Comment
Add comment · 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
2
Best Answer

Answer by Bampf · Sep 07, 2010 at 10:48 AM

As the final argument to the GUI.Button call, you can specify a GUIStyle.

Declare a public GUIStyle in your script, and add it as the third argument to your call:

GUI.Button(Rect((Screen.width/2)-25,Screen.height-30,50,25), back_button, myGuiStyle)

By default the GUIStyle will have no background textures defined for the control, so you should only see your own texture.

(Note about previous answer: a GUISkin consists of many GUIStyles, so it's a great way to create your own "look" for different types of controls. If you are only dealing with a couple control types you can get by with just GUIStyles.)

Comment
Add comment · 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
1

Answer by frogsbo · Jun 09, 2014 at 10:19 AM

The above answers are not complete and simple for a novice, and combined with my attention span of a fly, convolute answers is potenchil inefficient... you have to use GUIstyle.none

this one: if (GUI.Button(Rect(320,10,240,60),myTexture2D,GUIStyle.none)){ etc }

so here is an example of a custom grid using a texture, clic wherever on texture grid it will print the button ofthe grid pressed:

 function OnGUI(){
 
 
 
 
                 var gridpixels = 20;//pixels per grid square
                 var gidxsquares = 12;//num squares in x direction
                 if (GUI.Button(Rect(320,10,240,60),grid of buttons texture,GUIStyle.none))
         {
                 var xpos = Input.mousePosition.x - 320 ;
                 var ypos = Screen.height - Input.mousePosition.y -10;
                 
                 var result =  Mathf.Floor(xpos / gridpixels) + Mathf.Floor(ypos / gridpixels)*gidxsquares + 1;//plus 1 at end for not zero first square
             
         }    
         
 
 }
Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

GUI.DrawTexture versus Graphics.DrawTexture 4 Answers

Why is my GUI pushed over to the right? 0 Answers

Possible to change GUI.Label fontsize without using GUIStyle? 1 Answer

how do i make my own GUI 1 Answer

GameObject duplicates every time my GUI button is pressed 1 Answer


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