- Home /
GUI Texture Touch Android
Hi guys,
I got a couple of GUI textures in 1 script and I want that each texture has his own function. By example. If you touch GUITexture_01, you go to Scene_01 and if you touch GUITexture_02, you go to Scene_02.
This is the script I use, but I couldn't find a solution.
var Season_01:Texture2D : Touch = Input.touches[0];
var Season_01Width:float = 100;
var Season_01Height:float = 100;
var Season_02:Texture2D : Touch = Input.touches[0];
var Season_02Width:float = 100;
var Season_02Height:float = 100;
function OnGUI(){
GUI.DrawTexture(Rect( (Screen.width - Season_01Width)*0.05,(Screen.height - Season_01Height)*0.3, Season_01Width, Season_01Height), Season_01);
GUI.DrawTexture(Rect( (Screen.width - Season_02Width)*0.15,(Screen.height - Season_02Height)*0.3, Season_02Width, Season_02Height), Season_02);
}
function Update () {
if(Input.touchCount >= 0) {
if(Season_01.phase == TouchPhase.Began)
{
Application.LoadLevel("Scene_01");
}
if(Season_02.phase == TouchPhase.Began)
{
Application.LoadLevel("Scene_02");
}
}
}
Someone who can tell me what I did wrong and can help me figure this out? Please HELP!.
Thanks in advance
Answer by androids · May 01, 2013 at 08:25 PM
I figured it out, but thanks for help. This is what it should be.
var MenuSkin:GUISkin;
var Season_01:Texture2D;
var Season_01Width:float = 100;
var Season_01Height:float = 100;
var Season_02:Texture2D;
var Season_02Width:float = 100;
var Season_02Height:float = 100;
function OnGUI () {
GUI.skin = MenuSkin;
if(GUI.Button(Rect( (Screen.width - Season_01Width)*0.05,(Screen.height - Season_01Height)*0.3, Season_01Width, Season_01Height), Season_01)){
Application.LoadLevel("Scene_01");
}
if(GUI.Button(Rect( (Screen.width - Season_02Width)*0.15,(Screen.height - Season_02Height)*0.3, Season_02Width, Season_02Height), Season_02)){
Application.LoadLevel("Scene_02");
}
}
I tried that, I changed 'theTransparentGUIStyle' in to '$$anonymous$$enuSkin', but it gives me the same error '$$anonymous$$ identifier: '$$anonymous$$enuSkin'.
So I did it in this way. But thanks a lot!
Answer by trs9556 · May 01, 2013 at 01:22 AM
I'm not sure how to do that with a drawTexture but you can use a Button with a custom skin. Inside that custom skin just make all the button styles a transparent image, doesn't have to be big can even be a few pixels; just 100% transparent.
Then just instead of GUI.DrawTexture use
if(GUI.Button(Rect( (Screen.width - Season_01Width)*0.05,(Screen.height - Season_01Height)*0.3, Season_01Width, Season_01Height), Season_01, theTransparentGUIStyle)){
Application.LoadLevel("Scene_01");
}
if(GUI.Button(Rect( (Screen.width - Season_02Width)*0.15,(Screen.height - Season_02Height)*0.3, Season_02Width, Season_02Height), Season_02, theTransparentGUIStyle)){
Application.LoadLevel("Scene_02");
}
Please excuse any errors, I code in C# not in JS, so I can't garentee that is copy and paste-able
It doesn't work, I have no idea what's wrong and how to correct this JS
Have you made a new gui style and named it theTransparentGUIStyle?
Yes I did, but it says, $$anonymous$$ identifier: 'theTransparentGUIStyle'.
Your answer
Follow this Question
Related Questions
GUITextures and Multi Touch 1 Answer
Touch Input with GUI Texture 1 Answer
GUI texture touch input problem 1 Answer
GuiTexture (Touch button) unfollow camera! 1 Answer
Touchscreen for unity 2 Answers