LoginSignup
5
3

More than 5 years have passed since last update.

uGUIでのスクロール位置をスクリプトから設定したいメモ

Posted at

前置き

・女の子の一覧とか、アイコンを動的にズラーッと並べたい状況が出来た
・ズラーッと並べた後に、スクロールの表示位置を変更したくなった
 ※スクロールビューのサイズを動的に設定してGameObject(アイコン等)を子にすると、デフォルトのスクロール位置が変な位置になった

対応1(ダメなやり方)

・ScrollRect.Contentの位置(RectTransform.localPosition)を計算して設定する
  → 計算処理が無駄+微妙にズレる

対応2(多分ベストなやり方)

・以下の属性で設定する
  ↑/↓: ScrollRect.verticalNormalizedPosition (0.0f ~ 1.0f)
  ←/→: ScrollRect.horizontalNormalizedPosition(0.0f ~ 1.0f)

参考

Unity Document-ScrollRect

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3