- Home /
Scrollbar is not appearing in my list, I am using Unity 4.6
void OnGUI() {
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(400), GUILayout.Height(250));
for (int i = 0; i < ItemList.Count; i++) {
GUI.Label(new Rect(BoxTile.x, (BoxTile.height * i) + BoxTile.y + BoxTile.height, BoxTile.width, BoxTile.height), ItemList[i].Title, style );
GUI.Label(new Rect(BoxDes.x, (BoxDes.height * i) + BoxDes.y + BoxDes.height, BoxDes.width, BoxDes.height), ItemList[i].Description, style );
GUI.Label(new Rect(BoxCost.x, (BoxCost.height * i) + BoxCost.y + BoxCost.height, BoxCost.width, BoxCost.height), ItemList[i].Cost, style );
if (GUI.Button(new Rect(BoxBtn.x, ((BoxBtn.height+15) * i)+ BoxBtn.y + BoxBtn.height+15, BoxBtn.width, BoxBtn.height), "x" )) {
ItemList.RemoveAt(i);
}
}
GUILayout.EndScrollView();}
I am trying to create a list of item where it will just keep expanding using GUIlabel, then I can use a scroll bar to scroll through the list of items in Unity Script vertically by using C#. However, it seemed like the scroll bar will not appear on my list.
With my limited knowledge in Unity, I am not sure how to make modification on this codes to show the scrollbar, can someone please show me some light on this? Thanks in advance.
Answer by AcE_fLoOdEr · Jan 16, 2015 at 08:53 AM
Just use the 4.6 UI Scrollbar.
1). right click in hierarchy
2). go to UI > Canvas (creates new canvas)
3). right click on the newly created 'Canvas' go to UI > Scrollbar
Your answer
Follow this Question
Related Questions
C# - set Size for ScrollView 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to change thickness of ScrollBar of GUILayout ScrollView? 0 Answers