- Home /
UIToolkit for Android
I am making a GUI for my android game project on Unity using the UIToolkit. The Sample Scenes (eg Kitchen Sink) works fine on the Unity Editor. But when I run the exact same sample scenes on the android device , it doesnt work. The Button Texture is slightly shifted from the actual Touch Region. I have tried different Android Devices, but the result is the same.
I tried accessing the Sprite Locations using a function like
public float getYpos(this IPositionable sprite )
{
if(sprite == null)
return ;
float toRet = sprite.position.y;
return toRet;
}
But it the code returns an no Value!
I even trie`d using the "IPositionablePositioningExtensions" and returning the Sprite location. But no Success. Although I am not sure how to use the 'IPositiona`blePositioningExtensions', I have just started a beginner in this field.
My Button Creation Looks something like this :
playButton = UIButton.create("playUp.png", "playDown.png",0,0);
playButton.positionCenter();
playButton.scale = new Vector3(0.4f,0.4f,0);
Here is a screenshot of how the sample scene looks on an android device. The Bounding box is the region where the Touch Works, while the Button texture is being rendered somewhere else.
The Button texture should have been in the center position, although it moves to some other position while the touch region remains where it should have been.
Answer by shrey-malhotra · Mar 10, 2013 at 06:16 AM
Added the following code to UI.cs
public static void setSize()
{
_uiCamera.orthographicSize = Screen.height / 2;
// Set the camera position based on the screenResolution/orientation
_uiCamera.transform.position = new Vector3( Screen.width / 2, -Screen.height / 2, -10.0f );
}
updated the _uicamera to static
private static Camera _uiCamera;
Call this set method once the scene/game has been loaded.
void Update () {
if(!uiCameraCorrected)
{
UI.setSize();
uiCameraCorrected = true;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613094126im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Android Textfield locks out input until esc 2 Answers
Andoid enter text without gui 1 Answer
Create a Button Scrollview 0 Answers
GUI Button for Android 1 Answer