Sunday, July 27, 2014

How to make the function ONGUI to handle both iphone and ipad

Below is the link i found
http://forum.unity3d.com/threads/screen-resolutions-first-iphone-question.108539/


  •  
  • var originalWidth = 480.0;  // define here the original resolution
  • var originalHeight = 320.0// you used to create the GUI contents
  • private var scale: Vector3;
  •  
  • var buttonSkin : GUISkin;
  •  
  • function OnGUI ()
  • {
  •     GUI.skin = buttonSkin;
  •    
  •     //scale buttons to the correct position depending on screen resolution
  •     scale.x = Screen.width/originalWidth; // calculate hor scale
  •     scale.y = Screen.height/originalHeight; // calculate vert scale
  •     scale.z = 1;
  •     var svMat = GUI.matrix// save current matrix
  •     // substitute matrix - only scale is altered from standard
  •    
  •     ///////////////////////Your Gui Code Here//////////////////////////////    
  •     if(GUI.Button (Rect (170,255,120,40)"Try Again"))//iphone
  •     //if(GUI.Button (Rect (225,325,120,40), "Try Again"))//web 
  •     {
  •         Application.LoadLevel ("level01");
  •     }
  •    
  •    
  •     // restore matrix before returning
  •     GUI.matrix = svMat; // restore matrix  
  • }
  •  
  • No comments:

    Post a Comment