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 eXtremeTY · Jan 17, 2013 at 06:27 PM · c#guiguitexturehitonmousedown

How to control GUITextures within a single C# script?

Hello guys, the thing is, I placed GUITexture in editor manually, not via code, because it's easy that way to keep them appearing on the same position even if resolution changes..

Now I can assign a simple C# to it, and there is a function void OnMouseDown() and that's cool, that's what I need..

Now the thing is, if I create like an empty game object, and assign a new C# script to it, and load GUITexture in it via code like.. -> public GUITexture button;

Then how can I access the same function, OnMouseDown for that particular GUITexture, namely button? Because I plan to have single C# where I would keep many GUITextures, and do different things depending on what GUITexture the user has clicked on.

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

1 Reply

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

Answer by iwaldrop · Jan 17, 2013 at 07:04 PM

What you want to do is make ONE of these GameObjects that has a GUITexture and your script on it, and make it a Prefab by dragging it to your Hierarchy window. Then you can drag those prefabs out into your scene and set the texture to whatever you want. They will all behave exactly the same. Call it a GUITextureButton, or something like that, so you don't get confused later when you want to have a different kind of GUITexture Prefab.

Comment
Add comment · Show 4 · 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 eXtremeTY · Jan 18, 2013 at 02:21 AM 0
Share

Cheers iwaldrop for reply, but I$$anonymous$$O that doesn't really solves my problem.. I am still not sure how I should go about creating a single C# to handle all my different GUITextures... :/ Thanks anyway ;)

avatar image iwaldrop · Jan 18, 2013 at 07:23 AM 1
Share

Hmm...It sounds to me like you already have. If you have a script that does something when you hit a button (GUITexture) then you're set. I don't really know what you mean when you say you want to have a single script 'keep many GUITextures'. If you could explain your problem better than maybe myself, or other very knowledgable people here, can help you out. :)

avatar image eXtremeTY · Jan 18, 2013 at 05:15 PM 0
Share

Imagine this.. I, in editor, simply drag-n-drop let's say, 8 GUITextures, for example, for building 8 different types of buildings.. Now, I don't want to create 8 different C# scripts, for each building and assign to them.. I want to create like an empty GameObject named like "UI_$$anonymous$$anager" or so, attach a single C# script to it, and in that C# script, control each and every GUITextures (in this example 8) so in that single C# i'd like to have in update() something like... clicked button1(guitexture) do this.. clicked button2(guitexture) do this... etc.. Hope this sounds more understandable :/

avatar image eXtremeTY · Jan 19, 2013 at 01:32 AM 0
Share

Nvm got it right :)

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

10 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

Related Questions

Toggle GuiTexture 1 Answer

Gui Texture Differences 1 Answer

ASPECT RATIO FILTER IN OnGUI? 3 Answers

show guitexture on button click 1 Answer

What am I doing wrong? C# 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