How To Auto Adjust height of GUI.BeginScrollView in unity 3d

Hi All,

Here is my GUI.Beginscrollview Code…

scrollPosition = GUI.BeginScrollView(new Rect(1000, 40, 140, 400), scrollPosition, new Rect(0, 0, 120, 3000));
		loadingMessage = "Loading...";
		if(listOfImages.Count > 1){
			for(int i=0; i<listOfImages.Count; i++){
				Texture2D myImage = (Texture2D)listOfImages*;*

GUILayout.Label(myImage,GUILayout.MaxHeight(100),GUILayout.MaxWidth(100));

  •  	}*
    
  •  	loadingMessage = "";*
    
  •  }*
    

GUI.EndScrollView();

  • }*
    I just want to make my scrollview to auto adjust its height… means respecting with no. of images…
    Thanx…

int scrollViewHeight = listOfImages.Count*100;

Put that in before you assign scrollPosition. I wasn’t clear if you wanted to adjust the height of the on screen rectangle for the scrollview or the scrollable area inside the scroll view. For the former just replace the height parameter (4th parameter) with scrollViewHeight for the first Rect instantiation and to change the height of the latter just replace the height parameter on the 2nd Rect instantiation i.e.

scrollPosition = GUI.BeginScrollView(new Rect(1000, 40, 140, 400), scrollPosition, new Rect(0, 0, 120, scrollViewHeight));