Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Drymarti111 · Jul 30, 2016 at 11:07 AM · gui.button

gui button textured how to

Hello!

I have that code:

if (GUI.Button(Rect(0,75,200,25), "Grass = "+grassAmount))

{

selectedBlock = grassBlock;

}

How can I change gui.button to mu own texture button in that code?

There are a lot of lines like this, well I prefer to stay with that code if its possible to make it as a texture. Please help~!

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
0

Answer by Ruben_Chris · Jul 30, 2016 at 11:32 AM

You could use GUI Style to achieve this:

Javascript:

 var myButtonStyle : GUIStyle;
 
 function OnGUI () {
     if (GUI.Button(Rect(0,75,200,25), "Grass = "+grassAmount, myButtonStyle))
     {
     selectedBlock = grassBlock;
     }
 }

C#:

 public GUIStyle myButtonStyle;
 
 void OnGUI () {
     if (GUI.Button(new Rect(0,75,200,25), "Grass = "+grassAmount, myButtonStyle))
     {
     selectedBlock = grassBlock;
     }
 }

In the inspector where the script is attached, you can modify the normal, hover and active textures in the myButtonStyle dropdown.

I hope this helped you @Drymarti111.

Picture of how it looks in the inspector


capture.png (34.0 kB)
Comment
Add comment · Show 3 · 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 Drymarti111 · Jul 30, 2016 at 04:02 PM 0
Share

Wow thanks! But is there a way to just add var texture at the end of line? Because I have in that script more than 40 textures and it isn't working well with that ;/

I have var DirtText : Texture;

But when I want to add that for your: myButtonStyle It giving me error

How can i just add myowntexture(1 file texture) to this line?

avatar image Drymarti111 Drymarti111 · Jul 30, 2016 at 04:02 PM 0
Share

@Ruben_Chris

avatar image Ruben_Chris Drymarti111 · Jul 31, 2016 at 08:08 PM 0
Share

I see you have created the variable DirtText as a Texture. Have you tried creating it as a Texture2D?

 var DirtText : Texture2D;

If that doesn't work, can you copy and paste your error message? @drymarti111

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

64 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI Button Moving with a mouse 0 Answers

Why isn't WaitForSeconds working? 1 Answer

need help i have my mod for a game and im trying to make two of my gui.buttons work off a keybind 1 Answer

How do I destroy a GUI.button after it is clicked? 4 Answers

Button lag on android 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