Hi
I have written this code for my level select screen for my game, i basically have several grids and parents which i use as "pages" which are simply just offset from each other. Currently i use this for OnClick() and it successfully scrolls to the page offset.
Now i want to run this function once on first launch, so basically it will take the player back to the last page they were on, I have tried calling this in Start() but it doesnt scroll to the page? i guess that the 'SpringPanel.Begin' doesnt work on Start() or OnEnable()? i thought it would as ive seen others using it in those. What can i do? or am i just missing something.
void goToPage(int PageNumber)
{
int page = PageNumber;
int max = totalPages;
UICenterOnChild center = levelSelector.GetComponent<UICenterOnChild>();
UIPanel panel = levelSelector.GetComponent<UIPanel>();
UIScrollView sv = panel.GetComponent<UIScrollView>();
var child = levelSelector.transform.GetChild(page); //pass in page number
Debug.Log(child, child.gameObject);
Vector3 offset = -panel.cachedTransform.InverseTransformPoint(child.transform.position);
if (!sv.canMoveHorizontally) offset.x = panel.cachedTransform.localPosition.x;
if (!sv.canMoveVertically) offset.y = panel.cachedTransform.localPosition.y;
//Debug.Log("Xpos: " + offset, child.gameObject);
SpringPanel.Begin(panel.gameObject, offset, 6f);
}