Reputation: 803
I am instantiating many gameobjects in the unity by the c# code... And then make the scrollbar value 0 in order to scroll to the last object...but the scroll is landing me in the middle. Because of that there is a delay between unity and c# code. so the scrollbar changes before all the objects are shown.
How can I know that the user interface in unity is changed totally and I now can scroll to the end using a listener or something that tells me that you can now make the scroll and all objects are ready in the user interface??
MakeMessages();
Scrollbar.value = 0;
The scrollbar value is 0 before all messages are appearing in unity, so it is changing to 0.5 then.
Upvotes: 1
Views: 80
Reputation: 125245
You can detect Scrollbar value change with the Scrollbar.onValueChanged
. Register the event in the OnEnable
function and un-register it the OnDisable
function.
public Scrollbar sb;
void OnEnable()
{
//Register Scrollbar Event
sb.onValueChanged.AddListener(scollBarChanged);
}
//Called when Scrollbar value changes
private void scollBarChanged(float value)
{
Debug.Log("Input Changed");
}
void OnDisable()
{
//Un-Register Scrollbar Event
sb.onValueChanged.RemoveAllListeners();
}
Upvotes: 1