- Home /
Unity OnGUI elements have offset touch detections
Hello, I am a beginner-intermediate in C#, I have been working on a project for a while now, and I have this problem in trying to figure out, exactly why, the GUI elements are not fully responsive. I am not directly accessing anything in the Unity API related to touch. Instead I am using the function OnGUI and simply nesting the buttons in an if statement. The project is being built for Android. I have tested in on various android mobiles and tablets, all with the same result : The buttons only work when the touch is slightly higher than the position of the button. That is:
{Effective area}
{Actual position of button)
The following is a snippet of an onGUI function showing how I am generally implementing the buttons:
void OnGUI ()
{
if(a==0 & first==true & about==false)
{
if(GUI.Button (new Rect(Screen.width/2-Screen.width/12,Screen.height/2+Screen.height/7,Screen.width/6,Screen.height/7),"About"))
{
about=true;
}
}
if(about==true)
{
About();
}
else if(about==false)
{
stopheight=false;
up = Screen.height/6;
GUI.skin.horizontalScrollbarThumb.fixedWidth = Screen.width/7;
if(reference[0].checker==false & reference[1].checker==false & reference[2].checker==false & reference[4].checker==false & reference[5].checker==false & reference[6].checker==false & reference[7].checker==false& reference[8].checker==false & reference[9].checker==false & reference[10].checker==false & reference[11].checker==false & reference[12].checker==false& reference[13].checker==false & reference[14].checker==false & reference[15].checker==false & reference[16].checker==false& reference[17].checker==false& reference[3].checker==false)
{
GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.75f);
if(GUI.Button(new Rect(Screen.width-Screen.width/mover,Screen.height-Screen.height/7,Screen.width/6,Screen.height/7),options))option=true;
if(option==true)
{
mover = 1000f;
options = "Close";
toolbarStrings = QualitySettings.names;
toolbarInt = GUI.Toolbar(new Rect(0,Screen.height/7+bump-up, Screen.width-Screen.width/7.5f, Screen.height/7f), toolbarInt, toolbarStrings);
if(GUI.Button (new Rect(0,Screen.height/3.5f+bump-up,Screen.width/6,Screen.height/7),"FontSize"))fontmodify=true;
if(GUI.Button (new Rect(0,Screen.height/3.5f+bump-up+Screen.height/7,Screen.width/6,Screen.height/7),"Particles"))particles = !particles;
if(fontmodify==true){
GUI.skin.horizontalScrollbar.fixedWidth = Screen.width/1.5f;
GUI.skin.horizontalScrollbar.fixedHeight = Screen.height/7;
GUI.skin.horizontalScrollbarThumb.fixedWidth = Screen.width/12;
GUI.skin.horizontalScrollbarThumb.fixedHeight = Screen.height/7;
font = GUI.HorizontalScrollbar(new Rect(Screen.width/6,Screen.height/3.5f+bump-up, Screen.width-Screen.width/3.25f, Screen.height/7f),font,10,0,Screen.width/1.5f);
GUI.skin.button.fontSize=(int)font/10;
GUI.skin.label.fontSize=(int)font/10;
GUI.skin.box.fontSize=(int)font/10;
}
QualitySettings.SetQualityLevel(toolbarInt, false);
if(GUI.Button(new Rect(Screen.width-Screen.width/2.675f,Screen.height-Screen.height/7,Screen.width/6,Screen.height/7),options))
{
options = "Options";
mover = 2.675f;
option=false;
fontmodify=false;
}
}
if(a==1)
{
GUI.Box(new Rect(Screen.width/2-Screen.width/2,0,Screen.width,22), welcome);
if(Time.time-stopper1>12)a++;
}
if(first==true & a==0)
{
moveSpecific();
GUI.Box(new Rect(Screen.width/2-Screen.width/2,0,Screen.width,22), welcome);
}
else if(yes==true)
{
if(GUI.Button(new Rect(Screen.width/2-Screen.width/12,Screen.height-Screen.height/7,Screen.width/6,Screen.height/7), buttontext) & yes==true & first==false)
{
move = true;
originalpos = mycam.transform.position;
stopper=Time.time;
a++;
}
}
if(GUI.Button(new Rect(Screen.width-Screen.width/6,Screen.height-Screen.height/7,Screen.width/6,Screen.height/7), "Exit"))Application.Quit();
}
}
}
Your answer
Follow this Question
Related Questions
Where is Create->GUI Texture in Unity 1 Answer
How can i show the texture in the array? 2 Answers
Could I display XML content in Unity GUI interface? 0 Answers
Controlling GUI with Xbox 360 Controller 1 Answer
Show GUI.Label when touching trigger 4 Answers