Unity NGUI system uses ScrollRects to add scrollable elements to your game, but this scrollrect lacks the ability to restrict scrolling up past a certain point, something I determined to implement.
I had an idea: lets just check if ScrollRect.verticalNormalizedPosition
is 1, and if it is, set it to 1 (1 being the top part of the ScrollRect.)
public class scrollrectclamper: MonoBehaviour {
ScrollRect SR;
void Start () {
SR= gameObject.GetComponent<ScrollRect> ();
}
void Update(){
if (SR.verticalNormalizedPosition == 1) {
SR.verticalNormalizedPosition = 1; // WHY
}
}
}
This restricts scrolling even though I wouldn't even expect == 1
to work with a float
, a type infamous for its imprecision.
The description of verticalNormalizedPosition
says:
The vertical scroll position as a value between 0 and 1, with 0 being at the bottom.
But the function is broken only ever returns floats 1.0 if the scrollrect is at the top or above, and 0.0 if it's anywhere else.