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 Gilead7 · Aug 05, 2012 at 07:41 PM · c#onmousedownonmouseenteronmouseexit

Multiple GUI textures one script

I am making the control panel for my game. At the bottom of the screen, there will be various textures to do various tasks: put you into combat mode, various attack types, camp outside a city, open your quest journal, etc. I got one item working, but I'm unsure to make it work with multiple onMouseDown events. I would assume, you add a listener, but I thought you added it to onMouseEnter and Exit to add and remove.

Do you have a separate bool for each item and see if it was clicked? Any help would be appreciated. Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by OperationDogBird · Aug 05, 2012 at 09:07 PM

Are you using OnGUI or GUITexture?

If you are using OnGUI, use the builtin button with a style for the image(you can have separate images for hover, active, normal) see GUI Style.

 if(GUI.Button(rect,"Quest Journal",journalStyle))
 {
     Debug.Log("Clicked quest journal");
 }

If you are using GUITextures there is a built in function called HitTest() that make it act like a button. Check out GUIElement.HitTest.

 if(guiTexture1.HitTest(Input.mousePosition,Camera.main))
 {
     Debug.Log("Clicked gui texture 1");
 }

I suggest not using OnMouseEnter/Exit functions as they are intensive(those dont work on Phones either, for that reason).

Comment
Add comment · Show 5 · 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 Gilead7 · Aug 05, 2012 at 09:38 PM 0
Share

Thanks! What does guiTexture1 need to be defined as Texture2d or Texture or GuiTexture? What should the graphic element be set to? GUI? Texture? Clamp?

avatar image OperationDogBird · Aug 05, 2012 at 10:22 PM 0
Share

thats your guitexture, so like

 public var journalTexture:GUITexture;
 
 function Update()
 {
     if(Input.Get$$anonymous$$ouseButtonUp(0))
     {
         if(journalTexture.HitTest(Input.mousePosition,Camera.main))
         {
             Debug.Log("Journal Opened");
         }
     }
 }

$$anonymous$$y graphic is set to Texture, not Clamped.

avatar image Gilead7 · Aug 06, 2012 at 03:12 PM 0
Share

Thanks! I had heard that setting it to GUI was the way to go.

avatar image Gilead7 · Aug 06, 2012 at 11:34 PM 0
Share

Isn't Hit test part of the physics engine for 3d objects?

avatar image OperationDogBird · Aug 07, 2012 at 05:00 AM 1
Share

Not that i know of. You may be thinking of RaycastHit which uses raycast and collider, tho there is no physics involved. There is a link to the proper Hit Test in my original answer if you need the ref.

avatar image
0

Answer by TurboHermit · Aug 05, 2012 at 10:30 PM

I'd use GUI.Buttons if I were you. You can easily assign a texture to the button and what it does when you click it.

 var AwesomeTexture : Texture;
 var AnotherOne : Texture;

function OnGUI(){

 if (GUI.Button(Rect(10,10,50,50),AwesomeTexture)){
 //Do whatever
 }
 if (GUI.Button(Rect(20,500,100,100),AnotherOne)){
 //Do something else
 }

}

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

9 People are following this question.

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

Related Questions

OnMouseDown 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

OnMouseOver Problem 3 Answers

Changing the Mouse's Range for OnMouse events 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