Skip to content

Instantly share code, notes, and snippets.

@marcelschmidtdev
Created June 19, 2017 15:33
Show Gist options
  • Save marcelschmidtdev/bd42965967cd02a9f3b286ab4dbbf8cc to your computer and use it in GitHub Desktop.
Save marcelschmidtdev/bd42965967cd02a9f3b286ab4dbbf8cc to your computer and use it in GitHub Desktop.
Center element of scroll list
using UnityEngine;
using UnityEngine.UI;
public static class ScrollRectExtensions
{
public static void SnapTo (this ScrollRect rect, Transform target)
{
rect.content.anchoredPosition = rect.transform.InverseTransformPoint (rect.content.position) - rect.transform.InverseTransformPoint (target.position);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment