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
0
Question by pigi5 · Jan 17, 2011 at 10:45 PM · guitextureclickdraw

Can you use GUI.DrawTexture to make a clickable button

I am using the GUI.DrawTexture to make a gui texture appear so that it overlaps two cameras, but the script I am using to click on it is not working since I have changed to using this function instead of having a gui texture in the project panel. How can I make this clickable? I am using the OnMouseUp function currently.

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 khayati · May 19, 2013 at 01:12 PM 0
Share

Good, Can i put two pictures to make buton ?

avatar image ExTheSea · May 19, 2013 at 01:13 PM 0
Share

I converted your answer to a comment. Next time please use the comments to reply to someone. The answers are only used to answer the main question.

3 Replies

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

Answer by Ranza · Jan 17, 2011 at 11:08 PM

Probably the best idea is to use the Rect coordinates that you're passing to the DrawTexture function.

Try something like this:

Rect r = new Rect(x,y,width,height);
GUI.DrawTexture(r, texture);
Input.GetMouseButton(0)
{
    if (r.Contains(Event.current.mousePosition)) DoStuff();
}

If your graphics is static you may also want to put Rect in the class body.

Comment
Add comment · Show 1 · 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 lampshade · Jan 25, 2011 at 10:46 PM 0
Share

Excellent Post!

avatar image
5
Best Answer

Answer by Flynn · Jan 17, 2011 at 11:11 PM

There are three ways:

Use OnMouseUp as you said, and compare Input.MousePosition at that location to the rect of your texture.

Use a normal button, but replace the text section with your texture, and place a third parameter with the value : "label". This will make your button render as a label, and also use the texture as its content.

Place a button over your texture using the same rect. Make the text of the button blank, and add the label parameter as before. This will create an invisible button above your texture which can be used instead.

Hope this helps -- Flynn

Comment
Add comment · Show 1 · 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 hotshot03 · Sep 17, 2012 at 06:54 AM 0
Share

it helped... tnx :)

avatar image
3

Answer by maikonfarias · Feb 06, 2014 at 12:45 PM

Hi, for creating a simple texture as button I use this code, for me it looks simple.

C#:

 Rect position = new Rect(x,y,width,height);
 GUI.DrawTexture(position , texture);
 if (GUI.Button(position , "", new GUIStyle()))
 {
   DoStuff();
 }

I use the same rect to draw a button with a new empty GUIStyle, making the actual button invisible but still working for click/touch.

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 DrDecipher · Aug 14, 2014 at 07:14 AM 0
Share

$$anonymous$$aikon, Brilliant!!!

avatar image ifmamaif · Aug 02, 2015 at 05:21 PM 0
Share

Thank you , you save me !

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GUITexture Button? 1 Answer

GUITexture click detection problem 1 Answer

Help with destroying guiRect? 0 Answers

GUI text appears behind drawn texture. 0 Answers

Getting Error "DrawGUITexture: Texture is Null" when using Graphics.DrawTexture in OnGUI() 2 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