Author Topic: SpringPanel Begin doesnt work in Start()  (Read 1984 times)

coxy17

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
SpringPanel Begin doesnt work in Start()
« on: May 30, 2017, 09:46:21 AM »
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.

  1. void goToPage(int PageNumber)
  2.     {
  3.                 int page = PageNumber;
  4.                 int max = totalPages;
  5.  
  6.                 UICenterOnChild center = levelSelector.GetComponent<UICenterOnChild>();
  7.                 UIPanel panel = levelSelector.GetComponent<UIPanel>();
  8.  
  9.                         UIScrollView sv = panel.GetComponent<UIScrollView>();
  10.  
  11.                         var child = levelSelector.transform.GetChild(page); //pass in page number
  12.                         Debug.Log(child, child.gameObject);
  13.                        
  14.                         Vector3 offset = -panel.cachedTransform.InverseTransformPoint(child.transform.position);
  15.                         if (!sv.canMoveHorizontally) offset.x = panel.cachedTransform.localPosition.x;
  16.                         if (!sv.canMoveVertically) offset.y = panel.cachedTransform.localPosition.y;
  17.                        
  18.                         //Debug.Log("Xpos: " + offset, child.gameObject);
  19.                         SpringPanel.Begin(panel.gameObject, offset, 6f);
  20.                
  21.     }
  22.  

coxy17

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: SpringPanel Begin doesnt work in Start()
« Reply #1 on: June 02, 2017, 02:27:33 AM »
It doesnt matter now, i figured it out, i just ran it once in Update() and then used 'CenterOn' to get my page to load.