- Home /
UI elements change position
Hi there, I have a problem with UI elements. I made an menu composed from ui elements, then i tryied my application on my Samsung Galaxy S3. Everything went normal, but when i tryied the same app on another smartphone(with a different resolution) the ui elements were outside of the screen.I want ya'll to know that i've already looked through similarly questions, but nothing helped me. I have the following code: void OnGUI() { float rx = Screen.width / 1080.0f; float ry = Screen.height / 1920.0f; Matrix4x4.TRS(new Vector3(0,0,0),Quaternion.identity,new Vector3(rx,ry,1));
GUI.skin = GameSkin;
if (GUI.Button (ResizeGUI (GenerateRect), "GENERATE"))
GenerateNumbers ();
}
Rect ResizeGUI(Rect _rect)
{
float FilScreenWidth = _rect.width / 1080;
float rectWidth = FilScreenWidth * Screen.width;
float FilScreenHeight = _rect.height / 1920;
float rectHeight = FilScreenHeight * Screen.height;
float rectX = (_rect.x / 1080) * Screen.width;
float rectY = (_rect.y / 1920) * Screen.height;
return new Rect(rectX,rectY,rectWidth,rectHeight);
}
Sorry for bad english.
Your answer
Follow this Question
Related Questions
Unity5 new UI render problem on Android 1 Answer
ScrollView disappears shortly after starting the game (Android) 1 Answer
Unity 5 GUI fllickering, artefacts on Android 3 Answers
Vertical scrolbar unity android 0 Answers
Screen space canvas not resizing correctly when android device is rotated 0 Answers