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 lemiwinks · Sep 21, 2013 at 03:17 PM · guitexture

reference Gui texture outside script

hey guys, im trying to make some simple gui texture buttons that when clicked, zooms in and out the camera. one button is zoom in, another is zoom out. now im trying to reference the button in a script which is attached to the camera already. ive tried some methods like void onmousedown however im not sure how to reference gui textures outside the script? any help would be great

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 ArkaneX · Sep 21, 2013 at 03:23 PM 0
Share

What do you mean outside the script?

avatar image lemiwinks · Sep 21, 2013 at 03:29 PM 0
Share

sorry should of been clearer, i mean the script is not attached to the gui textures, its attached to a camera but id like to reference the textures by checking if they have been clicked

1 Reply

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

Answer by ArkaneX · Sep 21, 2013 at 03:37 PM

Assuming you have two texture variables (textureZoomIn and textureZoomOut) in your script attached to camera, then you need to do:

 void OnGUI()
 {
     if (GUI.Button(new Rect(0, 0, 100f, 30f), textureZoomIn))
     {
         ZoomIn();
     }
     if (GUI.Button(new Rect(0, 32f, 100f, 30f), textureZoomOut))
     {
         ZoomOut();
     }
 }

UPDATE: when writing above snippet, I was thinking of more common way of using textures in GUI buttons. For your case different solution is required:

 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (ZoomIN.HitTest(Input.mousePosition))
         {
             ZoomIn();
         }
         if (ZoomOUT.HitTest(Input.mousePosition))
         {
             ZoomOut();
         }
     }
 }
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 lemiwinks · Sep 21, 2013 at 04:05 PM 0
Share

i have them attached to the script by using public GUITexture ZoomIN; public GUITexture ZoomOUT;

and then i have attached guitextures in the editor

avatar image lemiwinks · Sep 21, 2013 at 04:09 PM 0
Share

also this does work, however not exactly what i meant.

http://i.imgur.com/gnVE5j5.png

as you can see with your method i now have 2 buttons in the upper left which are recognised when clicked. However i want the two buttons on the right to be zoom in and zoom out.

avatar image ArkaneX · Sep 21, 2013 at 04:28 PM 0
Share

Answer updated.

avatar image lemiwinks · Sep 21, 2013 at 04:45 PM 0
Share

great stuff, thats perfect for what i needed =D

avatar image ArkaneX · Sep 21, 2013 at 04:51 PM 0
Share

I've just thought about one more thing - transparent parts of GUI texture. Googling a bit I found this question - please take a look at the answer if you need a solution. It's about finding opaqueness of pixel under mouse, and ignoring click if it is fully transparent.

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

16 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

Related Questions

How to do you add GUI texture using a script?and position it to the left (regardless of the reso.) 1 Answer

Null reference exception[SOLVED] 1 Answer

GUItexture change on mouseenter 3 Answers

How do I change the font and color of GUI text? 0 Answers

Creating a component from a button click 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