Advertisement
obernardovieira

[Unity3D] Percentage of screen size

Mar 4th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. var besquerda;
  4. var bdireita;
  5.  
  6. static function percent(vertical : boolean, percent : float) : float {
  7.     if(vertical == true)
  8.         return Screen.height*percent/100.0;
  9.     else
  10.         return Screen.width*percent/100.0;
  11. }
  12.  
  13. function OnGUI() {
  14.     if (GUI.Button(besquerda,"<"))
  15.         Debug.Log("Esquerda");
  16.     else if (GUI.Button(bdireita,">"))
  17.         Debug.Log("Direita");
  18. }
  19.  
  20. function Start () {
  21.     var altura : float = percent(false,5.0);
  22.     var largura : float = percent(true,80.0);
  23.     besquerda = Rect (percent(false,5.0), percent(true,10.0), altura, largura);
  24.     bdireita = Rect (percent(false,90.0), percent(true,10.0), altura, largura);
  25. }
  26.  
  27. function Update () {
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement