- Home /
How to make a GUI Texture clickable when it's a gameobject animted through iTween?
I have some "buttons" I've made wizz around using iTween, I need them to be clickable to call functions, however they are GUITexture GameObjects, from the GameObject menu.
Can't for the life of my figure out how to add function calls like
SwitchToSettingsScreen();
to a GUITexture in the same script with the var
var btnSettings : GameObject;
Is it even possible? The example I downloaded from iTween has "1 Player" "2 Player" "buttons" but they are not actually buttons, there is just one:
function Update(){
if(Input.GetMouseButtonDown(0)){
SwitchToSettingsScreen();
}
}
blanketing the screen for any type of click.
This is the sort of thing going on in my mind:
function Update(){
if (btnSettings.Input.GetMouseButtonDown(0)){
Debug.Log("clicked");
//SwitchToSettingsScreen();
}
}
But obviously this brings up the error:
'Input' is not a member of 'UnityEngine.GameObject'.
My code-fu isn't yet strong enough to make this work
Answer by jonas-echterhoff · Jul 04, 2011 at 11:00 AM
GUITextures will call OnMouseDown() functions on all their components. So if you just attach a script with an OnMouseDown function to the GameObject with the GUITexture, it will be called whenever the GUITexture is clicked on.
The problem I have with this is if I make the function it's calling into a Static Function in the related script, everything breaks.
It recursively asks me to make every function in the other script a static var / function
Well, why make the function static in the first place then?
Sorry, I was under the impression that I need to make the function static in the other script for it to be called from the script on the button. Also the function I'm calling has other functions inside it. Is there another way to call functions from other scripts in a scene?
Answer by Unamine · Jul 04, 2011 at 11:07 AM
You can create a custom button, which changes the standard version of the button with an image of your choice, for it creates a GUI skin and create the needed amount of buttons in the area of custom styles.
I hope I have helped
Your answer
Follow this Question
Related Questions
Assigning Texture2D as GUI.Button 4 Answers
Scale a GUITexture from its center 1 Answer
iTween on GuiTexture 1 Answer
how to move or fade GUITextures with iTween 2 Answers
How to slide UVs of a GUI Texture 4 Answers