2016-06-21 10 views
4

Ich habe eine GUI Ich zeichne, wenn Sie auf den Shop-Button klicken, gibt es GUI.BeginScrollView und innerhalb einiger Schaltflächen, jedenfalls habe ich die scrollview arbeiten nur in Unity-Editor, wenn ich laufe am Telefon funktioniert es nicht, ich sehe die Tasten, aber ich habe keinen Scroller.Unity C# scrollbar GUI.BOX funktioniert nicht auf Android

using UnityEngine; 
    using System.Collections; 
    using UnityEngine.UI; 

    public class Shop : MonoBehaviour 
    { 
     private bool PopUp; 
     public string Info; 
     public Touch touch; 
     public Vector2 scrollPosition = Vector2.zero; 

     void Update() 
     { 
      if (Input.touchCount > 0) 
      { 
       touch = Input.touches[0]; 
       if (touch.phase == TouchPhase.Moved) 
       { 
        scrollPosition.y += touch.deltaPosition.y; 
       } 
      } 

     } 

     void OnGUI() 
     { 
      Rect rect = new Rect(Screen.width/4, Screen.height/4, Screen.width/2, Screen.height/2); 
      Rect close = new Rect(Screen.width/4 + Screen.width/2, Screen.height/4, Screen.width/30, Screen.width/30); 
      Rect a= new Rect(0, 0, Screen.width/2 - 2 * Screen.width/50, Screen.height/10); 
      Rect b= new Rect(0, Screen.height/10, Screen.width/2 - 2 * Screen.width/50, Screen.height/10); 
      Rect c= new Rect(0, 2 * Screen.height/10, Screen.width/2 - 2 * Screen.width/50, Screen.height/10); 
      Rect d= new Rect(0, 3 * Screen.height/10, Screen.width/2 - 2 * Screen.width/50, Screen.height/10); 
      Rect e= new Rect(0, 4 * Screen.height/10, Screen.width/2 - 2 * Screen.width/50, Screen.height/10); 
      Rect f= new Rect(0, 5 * Screen.height/10, Screen.width/2 - 2 * Screen.width/50, Screen.height/10); 
      if (PopUp) 
      { 
       GUIStyle myStyle = new GUIStyle(GUI.skin.button); 
       float sizesc = Mathf.Sqrt(Mathf.Pow(Screen.width, 2) + Mathf.Pow(Screen.height, 2)); 
       myStyle.fontSize = (int)(0.015f * sizesc); 
       scrollPosition = GUI.BeginScrollView(rect, scrollPosition, new Rect(0, 0, 0, PlayerPrefs.GetInt("unlocked") * Screen.height/10f + 10)); 
       if (GUI.Button(a, "Buy a", myStyle)) 
       { 
//do something     
       } 
       if (GUI.Button(b, "Buy b", myStyle)) 
       { 
//do something 
       } 
       if (GUI.Button(c, "Buy c", myStyle)) 
       { 
//do something 
       } 
       if (GUI.Button(d, "Buy d", myStyle)) 
       { 
//do something 
       } 
       if (PlayerPrefs.GetInt("e") > 0) 
       { 
        if (GUI.Button(e, "Buy e", myStyle)) 
        { 
//do something 
        } 
       } 
       if (PlayerPrefs.GetInt("f") > 0) 
       { 
        if (GUI.Button(f, "Buy f", myStyle)) 
        { 
//do something 
        } 
       } 
       GUI.EndScrollView(); 
       if (GUI.Button(close, "X")) 
       { 
        PopUp = false; 
       } 
      } 
     } 

     public void onClick() 
     { 
      PopUp = true; 
     } 
    } 

Ich kann nicht verstehen, warum es nur auf UnityEditor und nicht auf meinem Android-Gerät funktioniert.

Antwort

4

Lösung veränderte sich diese Zeile:

scrollPosition = GUI.BeginScrollView(rect, scrollPosition, new Rect(0, 0, 0, PlayerPrefs.GetInt("unlocked") * Screen.height/10f)); 

was bedeutet, Anzahl der Tasten * Höhe des Knopfes, um:

scrollPosition = GUI.BeginScrollView(rect, scrollPosition, new Rect(0, 0, 0, PlayerPrefs.GetInt("unlocked") * Screen.height/10f + 10)); 

Gerade Herstellung der Gui.BeginScrollView größer ein Bit von der Länge der Tasten.