- Home /
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 =)
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.
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 ;)
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. :)
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 :/
Your answer
Follow this Question
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