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 tried using the "IPositionablePositioningExtensions" and returning the Sprite location. But no Success. Although I am not sure how to use the 'IPositionablePositioningExtensions', 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.
Found the solution. The onAwake method returns a different screen size than the actual screen size.
So added the following code to the uiCamera in ui.cs file
This is called once the screen has been set up.