Button function Problems

Hi all,

Im having a problem about the button function.
I made a GUI button from start menu then loads up the game and it did well, but i dont want to use the background of the GUIButton and I manage to remove the main texture and link the button texture to GUITexture , but the original texture of the GUIbutton is is still appearing and i don’t have access re sizing and re positioning the gui texture. So I created a new script to attached to GUITexture (withoutGUIbutton) , and it works but the problem is my main character seems to appear way back -Y positon (im creating 2d game) , unlike the GUIButton it starts well without any problem. GUIButton problem is not appearing correct size and position after building and playing in tablet. GUITexture gives me the correct size and correct position. any advice and help? Please…


If you use GUITexture, you should scale objects independently for different display resolutions. I will write a small script(write on CSharp):

 //define here the original resolution. For it you set all position and the sizes of your GUITextures.
 public float origW = 1280;
 public float origH = 720;

 void Start() {
  float scaleX = (float)(Screen.width) / origW; //your scale x
  float scaleY = (float)(Screen.height) / origH; //your scale y
  //Find all GUITexture on your scene
  GUITexture[] textures =  FindObjectsOfType(typeof(GUITexture)) as GUITexture[];
  foreach(GUITexture myTexture in textures) { //find your element of texture
   Rect pixIns = myTexture.pixelInset; //your dimention of texture
   //Change size pixIns for our screen
   pixIns.x = pixIns.x * scaleX;
   pixIns.y = pixIns.y * scaley;
   pixIns.width = pixIns.width * scaleX;
   pixIns.height = pixIns.height * scaleY;
   //Sets new rectangle for our texture
   myTexture.pixelInset = pixIns;

If you want to create GUIButton with other texture, it is best of all to create new GUIStyle. In it you can change a texture. However, in most cases, it is better to create a set of styles: GUISkin. I hope that it will help you.