Scrollbar position focus issue[Solved]

using the old GUI.BeginScrollView basically i have this code:

scrollPosition = GUI.BeginScrollView (new Rect (0, Screen.height * 0.14f + 31, Screen.width + 50, Screen.height * 0.6f), scrollPosition, new Rect (0, Screen.height * 0.14f + 66 / 2, 0, 28 * numberOfPlayers - 15));
GUI.Label (new Rect (Screen.width * 0.05f + 40, Screen.height * 0.14f + 33, Screen.width - 20, 28 * numberOfPlayers - 5), playerName);

//used to print leaderboard name under one label
for (int i = 0; i < gameResponseObj.GetScoreList().Count; i++) 
{
    playerName = playerName + nxtLine;
}

not the entirety of the code but thats about most of what’s needed

Imagine you have a leaderboard you can scroll through and trying to automatically find my current rank; lets say the player rank is 500/2000 how would i scroll automatically to that position, been trying a lot of thing but can’t get it right; i know when to use the code just can’t get the position right, need help plz

It is necessary to move scroll to the necessary line item. But you remember that if the size of all scroll, for example, 3000, and the amount of its display on the screen, for example, 650, the maximum value of a line item of scroll on y will be 3000-650. Further I will write a small example (write on CSharp):

 //Create class for leader with parametr name and score
 public class Leader {
  public string name = "";
  public int score = 0;
 }
 //Create List of leaders(don't forget add "using System.Collection.Generic"). Of course, you can to create array
 public List<Leader> myLeaderBoard = new List<Leader>();

 private Vector2 scrollPosition = Vector2.zero;

 private string myName = "47"; //name for search

 //Update1: create string variable for all text information
 private string fullBoard = "";

 void Start() {
  //For example, initialization you leaders
  for(int i =0; i < 100; i++) {
   Leader tpLead = new Leader();
   tpLead.name = i.ToString();
   tpLead.score = 10 * i;
   myLeaderBoard.Add(tpLeader)
  }
  //Update1: Fill string variable
  fullBoard = "";
  for(int i = 0; i < myLeaderBoard.Count; i++) {
   if (fullBoard != "") {
    fullBoard = fullBoard + "

";
}
fullBoard = fullBoard + myLeaderBoard_.name + ": " + myLeaderBoard*.score.ToString();_
_
}_
_
}_
void OnGUI() {
_
//Update1: create height text of board. For default you use “label” style*_
float hBoard = GUI.skin.label.CalcHeight(new GUIContent(fullBoard), Screen.width + 50);
//Create leaderboard, 3td parameyr in scroll: area of full scroll
scrollPosition = GUI.BeginScrollView (new Rect (0, Screen.height * 0.14f + 31, Screen.width + 50, Screen.height * 0.6f), scrollPosition, new Rect (0, 0, Screen.width + 50, hBoard));
GUI.Label(new Rect(0, 0, Screen.width + 50, hBoard), fullBoard);
GUI.EndScroll();
//Create button for search
if (GUI.Button(new Rect(0, 0, 100, 30), “Search”)) {
//Search name in list
for(int i = 0; i < myLeaderBoard.Count; i++) {
if (myName == myLeaderBoard*.name) {*
scrollPosition.y = i * hBoard / myLeaderBoard.Count; //Update1: new calculate
if (scrollPosition.y > hBoard - Screen.height * 0.6f) {
scrollPosition.y = hBoard - Screen.height * 0.6f;
}
break;
}
}
}
}
I hope that it will help you.