why? and how can I move scrollbar to the bottom (to show most recent message) automatically when new message posted and scroll bar generated?
Thanks.
why? and how can I move scrollbar to the bottom (to show most recent message) automatically when new message posted and scroll bar generated?
Thanks.
You need to modify the scrollPosition variable. It is a Vector2. I don’t know what your code looks like, but I am assuming that you are adding a new label to your list of messages. When you get a new message you would add the height of that label to the ‘y’ property of the scrollPosition variable. You only want to call this when you get a message. If you have it called on Update, it will continue to repeat and make the ScrollView unusable.
void NewMessageReceived()
{
scrollPosition = new Vector2(scrollPosition.x, scrollPosition.y + messageLabelHeight);
}
@avidesk Thanks for reply. Yes I am using vector2.zero and label for list of messages. It was in the unity official reference. But I remember, when I use this method in unityscript, it automatically scroll to down when new message generated, but I now writing in C#, it doesn’t.
anyway, your method solved problem. I added one line in OnGUI.
for(int a = 0; a<entries.Count; a++){
GUILayout.Label(entries[a]);
NewMessageReceived();
}
This can automatically catch what multiple line of messages generated, and adjust scrollbar down to it.