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 LANDO · Jan 21, 2011 at 02:15 AM · guicharactercontrollerguitexturegui.button

Assigning Texture2D as GUI.Button

I'm attempting to create a custom GUI from an Illustrator file which will control character movement. Here is a sample of the script I'm attempting to build:

// GUI active elements: var dPadTexture : Texture2D; var position : Rect;

function OnGUI () {

GUI.DrawTexture( position, dPadTexture ); GUI.Button(position, dPadTexture); }

My question is how to draw a Texture2D in the GUI and have it also function as a button, basically just creating a custom button graphic that inputs as a mouseEvent telling the character to move.

Here is a screenshot of the above code's result:alt text

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 LANDO · Jan 21, 2011 at 02:27 AM 0
Share

After doing some reading it seems this may work however I haven't found a way to implement it:

myVar = GUILayout.Button("Test dPad", myVar, "Texture2D");

avatar image LANDO · Jan 21, 2011 at 02:40 AM 0
Share

To replicate the problem I'm encountering use this script: "// Draws a button with an image and a button with text var tex : Texture;

function OnGUI() { if(!tex) { Debug.LogError("No texture found, please assign a texture on the inspector"); }

if(GUILayout.Button (tex)) { Debug.Log("Clicked the image"); }

if(GUILayout.Button ("I am a regular Automatic Layout Button")) { Debug.Log("Clicked Button"); } }"

Script found @ http://unity3d.com/support/documentation/ScriptReference/GUILayout.Button.html

4 Replies

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

Answer by Simon Wittber · Jan 21, 2011 at 02:42 AM

I think what you want is this:

GUI.Button(position, dPadTexture, "label")

This will create a button with the texture, and make it look like a label (no button border).

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 LANDO · Jan 21, 2011 at 04:49 PM 0
Share

This is exactly what I was looking for, thanks for the help! I'll post my final working code at the end of the day.

avatar image Proportion · May 14, 2011 at 10:13 AM 0
Share

just letting you know this helped me out a bundle too, thanks for that :D

avatar image
1
Best Answer

Answer by Jessy · Jan 21, 2011 at 02:41 AM

I can't really tell what you're asking. Your DrawTexture doesn't look like it's helping anything. And you need an if statement around your button code, if you want it to be functional and not just graphical.

http://unity3d.com/support/documentation/ScriptReference/GUI.Button.html

Edit: I'm assuming now that you're talking about the default style. Get rid of it.

var style : GUIStyle;

function OnGUI () { GUI.Button(position, dPadTexture, style); }

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 LANDO · Jan 21, 2011 at 04:51 PM 0
Share

Good call on the GUIStyle, I got rid of the default style and everything is working great! Thanks!

avatar image
0

Answer by charnew · Dec 26, 2011 at 09:05 AM

if (GUI.Button(new Rect(100, 10, 200, 250), nameofthebutton)) {}

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
0

Answer by ivan1233 · Feb 27, 2013 at 08:14 PM

This is my way, I do it like this:

1)Create GUISkin...

2)Write script, or copy and paste this JavaScript:

var Skin : GUISkin;

 function OnGUI {
     GUI.skin = Skin;
     //button code...
 }

Good Luck, Ivan!

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

Make more buttons appear, on button click. 1 Answer

dynamic GUI Texture.. clipping and rotation HUD 1 Answer

script to create gui when detection collision between cube and first controler person ?? 1 Answer

WorldToScreenPoint returns the same value when facing the opposite direction. 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