Search Unity

Scrolling to the last element

Discussion in 'UGUI & TextMesh Pro' started by nsmith1024, Aug 13, 2018.

  1. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Hello,

    Im making a small chat using a unity Scroll Rect.

    Each element in the rect contains an object, this object contains an Image, and a text containing whatever the user typed.

    Each time the user enters a new text, a new object containing their photo and whatever the typed is entered into the scroll rect. So the screen looks like this.
    ------------------------|||
    |PHOTO: TEXT |||
    |PHOTO: TEXT |||
    |PHOTO: TEXT |||
    |------------------------|||

    If the user keeps making entries, eventually the last object containing the photo and text disappears off the bottom, and you cant see whatever was entered.

    I cant seem to scroll automatically so that when the last entry is made, it automatically scrolls so that one is visible at the bottom.

    Does anybody know how to do it?

    Thanks
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    myScrollRect.normalizedPosition = 1f;
    -- maybe you have to wait a frame to let the UI update first.
     
  3. Thunderkilll

    Thunderkilll

    Joined:
    Oct 30, 2018
    Posts:
    9
    myScrollRect.normalizedPosition
    myScrollRect.normalizedPosition is a Vector2D
     
  4. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Thanks for pointing out. The code should be:
    myScrollRect.normalizedPosition = new Vector2(myScrollRect.normalizedPosition.x, 1);


    BTW: I think you can achieve this goal more elegantly by configuring pivos correctly. But not entirely sure which pivots to set without testing.
     
  5. Thunderkilll

    Thunderkilll

    Joined:
    Oct 30, 2018
    Posts:
    9
    Hello,

    Im making a small chat using a unity Scroll Rect.

    Each element in the rect contains an object, this object contains an Image, and a text containing whatever the user typed.

    Each time the user enters a new text, a new object containing their photo and whatever the typed is entered into the scroll rect. Like you but I want the messages to load dynamically when I scroll top and down
    anyone has an idea ?
     
  6. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    So you want to load on demand?
    That wouldn't be too hard but if you also want to unload content it could become more difficult.
    However, this doesn't really match the topic of this thread, so I suggest to open a new thread for the question (you may leave a link to that thread here).
     
  7. Thunderkilll

    Thunderkilll

    Joined:
    Oct 30, 2018
    Posts:
    9
    I don't know how to do this
     
  8. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
  9. ConveyorXGames

    ConveyorXGames

    Joined:
    Sep 21, 2021
    Posts:
    2
    Thx dudes i needed this to make a console window.